检查iOS 6中是否安装了Google Maps App

jwk*_*knz 10 cocoa-touch google-maps objective-c uialertview ios

我试图找出如何处理此代码的结果,以查看是否在应用程序中安装了Google地图.

[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];
Run Code Online (Sandbox Code Playgroud)

UIAlertView在那里创建一个选项,如果它是或不是我希望给用户不同的选项.

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

提前致谢.

rck*_*nes 23

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

BOOL canHandle = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]];

if (canHandle) {
   // Google maps installed
} else {
   // Use Apple maps?
}
Run Code Online (Sandbox Code Playgroud)

  • 您需要将“comgooglemaps://”添加到您将在 iOS 9 中调用的应用程序 URL 方案列表中。只需将您将调用的 URL 添加到应用程序“info.plist”中的“LSApplicationQueriesSchemes”中 (2认同)

Jee*_*eet 5

以上适用于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];
Run Code Online (Sandbox Code Playgroud)