【问题标题】:Check if Google Maps App is installed in iOS 6检查是否在 iOS 6 中安装了 Google 地图应用
【发布时间】:2013-04-15 10:29:05
【问题描述】:

我正在尝试弄清楚如何处理此代码的结果,以查看应用中是否安装了 Google 地图。

[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];

我正在创建一个带有选项的UIAlertView,如果是或不是,我希望为用户提供不同的选项。

如何获取上面代码的结果并将其转换为 BOOLEAN?

提前致谢。

【问题讨论】:

    标签: ios objective-c google-maps cocoa-touch uialertview


    【解决方案1】:

    结果已经是 canOpenURL: 一个布尔值:

    BOOL canHandle = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]];
    
    if (canHandle) {
       // Google maps installed
    } else {
       // Use Apple maps?
    }
    

    【讨论】:

    • 酷,现在说得通 - 从来没有见过这样的:-)
    • 它返回 false 并且 google 地图已经存在于 iphone 中是否还有其他适用于 ios9 的解决方案???
    • 您需要将 comgooglemaps:// 添加到您将在 iOS 9 中调用的应用程序 url 方案列表中。只需将您将要调用的 URL 添加到您的应用程序中的 LSApplicationQueriesSchemes info.plist
    • 我在 LSApplicationQueriesSchemes(plist 文件)中添加了 comgooglemaps://。但它仍然给出错误的结果。谷歌地图在我的 iPhone 上可用,但它返回错误
    • 在 iOS9.0 及更高版本中,我们必须从“comgooglemaps://”中删除“//”。
    【解决方案2】:

    iOS 9.0 以上

    第 1 步。 在您的应用 info.plist 中的 LSApplicationQueriesSchemes 中添加 comgooglemaps

    第 2 步。

    BOOL isGoogleMap = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps://"]];
    UIAlertView *alert;
    
    if(isGoogleMap)
    {
        alert = [[UIAlertView alloc]
                 initWithTitle:@"Get Directions"
                 message:@"Show Map"
                 delegate:self
                 cancelButtonTitle:@"Cancel"
                 otherButtonTitles:@"View in Apple Maps", @"View in Google Maps", nil];
    }
    else
    {
        alert = [[UIAlertView alloc]
                 initWithTitle:@"Get Directions"
                 message:@"Show Map"
                 delegate:self
                 cancelButtonTitle:@"Cancel"
                 otherButtonTitles:@"View in Apple Maps", nil];
    }
    alert.tag = 1010;
    [alert show];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多