我正在尝试弄清楚如何处理此代码的结果,以查看应用程序中是否安装了Google Maps。
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];
我正在创建一个带有选项的UIAlertView
,如果选中或未选中,我希望为用户提供不同的选项。
如何将上述代码的结果转换为布尔值?
先行感谢。
我正在尝试弄清楚如何处理此代码的结果,以查看应用程序中是否安装了Google Maps。
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];
我正在创建一个带有选项的UIAlertView
,如果选中或未选中,我希望为用户提供不同的选项。
如何将上述代码的结果转换为布尔值?
先行感谢。
结果已经是canOpenURL:
的布尔值:
BOOL canHandle = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]];
if (canHandle) {
// Google maps installed
} else {
// Use Apple maps?
}
iOS 9.0及以上版本
步骤1:在应用程序的info.plist中将comgooglemaps添加到LSApplicationQueriesSchemes中
步骤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];
comgooglemaps://
添加到您在 iOS 9 中将调用的应用程序 URL 方案列表中。只需将要调用的URL添加到应用程序的info.plist
中的LSApplicationQueriesSchemes
中即可。 - rckoenes