2013-04-15 63 views
9

我想弄清楚如何处理这段代码的结果,看看谷歌地图是否安装在应用程序中。检查谷歌地图应用程序是否安装在iOS 6

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

我在那里创建一个与选项UIAlertView,如果它是或不是我想给用户不同的选择。

如何将上述代码的结果转换为布尔值?

在此先感谢。

回答

21

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

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

if (canHandle) { 
    // Google maps installed 
} else { 
    // Use Apple maps? 
} 
+0

酷,现在是有道理的 - 从来没有见过这样的:-) –

+0

完美的作品 –

+0

返回false和谷歌地图已经存在于iPhone 是有ios9任何其他的解决办法??? –

4

以上的iOS 9.0

第1步:在LSApplicationQueriesSchemes添加comgooglemaps在您的应用程序的info.plist

第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]; 
相关问题