Check if Google Maps App is installed in iOS 6

家住魔仙堡 提交于 2019-12-03 12:07:34

The result is already of canOpenURL: a boolean:

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

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

Above for iOS 9.0

Step 1. Add comgooglemaps in LSApplicationQueriesSchemes in your apps info.plist

Step 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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!