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)
以上适用于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)
| 归档时间: |
|
| 查看次数: |
5820 次 |
| 最近记录: |