检查是不是在 iOS 6 中安装了 Google 地图应用

Posted

技术标签:

【中文标题】检查是不是在 iOS 6 中安装了 Google 地图应用【英文标题】: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?

提前致谢。

【问题讨论】:

【参考方案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];

【讨论】:

以上是关于检查是不是在 iOS 6 中安装了 Google 地图应用的主要内容,如果未能解决你的问题,请参考以下文章

如果在 Internet Explorer 中安装了 Lync 插件,我如何检查 Javascript?

sh Core OS中安装了Python 3.6.0

从浏览器检测是不是在 Android 中安装了特定应用程序

Android:如何知道是不是已经使用 adb 在 android 设备中安装了任何应用程序?

如何判断 Linux 机器上的目录是不是在 Java 中安装了外部文件系统?

当设备中安装了 FB Native App 时,无法使用 Facebook ios sdk v3 进行授权