随记(二)--是否能打开手机某个应用

 1 NSLog(@"%d",[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]);
 2  
 3         if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap:"]]){
 4             NSString *urlString = [NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:%@&mode=transit",
 5                                    _startCoor.latitude, _startCoor.longitude, _endCoor.latitude, _endCoor.longitude, _title.text];
 6             
 7             urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 8             NSURL *url = [NSURL URLWithString:urlString];
 9 
10             [[UIApplication sharedApplication] openURL:url];
11         } else {
12             UIAlertController *appContro = [UIAlertController alertControllerWithTitle:@"提示" message:@"您是否立即前往APPStore安装!" preferredStyle:UIAlertControllerStyleAlert];
13             UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"稍后安装" style:UIAlertActionStyleDefault handler:nil];
14             UIAlertAction *download = [UIAlertAction actionWithTitle:@"立即安装" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
15                 NSString *appStr = [NSString stringWithFormat:@"https://appsto.re/cn/ce98A.i"];
16                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStr]];
17             }];
18             [appContro addAction:download];
19             [appContro addAction:cancel];
20             
21             [self presentViewController:appContro animated:YES completion:nil];
22         }
23     }];

 NSLog(@"%d",[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]); 

开始这行不管手机上是否安装le百度地图应用,返回结果都会是NO;因项目中对该链接是不信任的,从而导致canOpenURL返回都是NO;

打开info.plist 添加LSApplicationQueriesSchemes

posted @ 2016-03-14 11:19  Gary随风  阅读(280)  评论(0编辑  收藏  举报