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

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

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

我正在创build一个UIAlertView在那里的选项,如果是或不是我想给用户不同的选项。

我如何把上面的代码的结果变成一个BOOLEAN?

提前致谢。

结果已经canOpenURL:布尔:

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

以上为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];