iOS app 打开第三方接口、拨打电话、打开地图第三方app等

飞猪机票预订:https://h5.m.taobao.com/trip/flight/search/index.html?spm=181.7474825.1998613473.1&ttid=&_preProjVer=0.1.69&_projVer=1.1.40

飞猪火车票/汽车票预订:https://h5.m.taobao.com/trip/train/search/index.html?_projVer=0.5.62

美团购买/搜索:http://i.meituan.com/s/liupanshui- 加上要搜索商品的名称

淘宝购买/搜索:https://s.m.taobao.com/h5?event_submit_do_new_search_auction=1&_input_charset=utf-8&q=  等于后面加上需要搜索商品的名称

中国天气网:http://wx.weather.com.cn/mweather/101260801.shtml#1

微信公众号链接:mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzIzMTQ2NTEyNA==&scene=23#wechat_redirect(可将biz改为自己的openid


拨打电话

1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示
NSMutableString * str=[[NSMutableStringallocinitWithFormat:@"tel:%@",@"186xxxx6979"];

//NSLog(@"str======%@",str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    

2,这种方法,打完电话后还会回到原来的程序,也会弹出提示,推荐这种
NSMutableString * str=[[NSMutableStringallocinitWithFormat:@"tel:%@",@"186xxxx6979"];
    
UIWebView * callWebview = [[UIWebViewallocinit];
    [callWebview 
loadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:str]]];
    [
self.viewaddSubview:callWebview];


3,这种方法也会回去到原来的程序里(注意这里的telprompt),也会弹出提示
NSMutableString * str=[[NSMutableStringallocinitWithFormat:@"telprompt://%@",@"186xxxx6979"];
 
//NSLog(@"str======%@",str);
    [[UIApplicationsharedApplicationopenURL:[NSURLURLWithString:str]];


//地图第三方

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

//高德

 [alertController addAction:[UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *stringUrl = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&backScheme=%@&sname=%@&dname=%@&dev=0&m=0&sid=BGVIS1&did=BGVIS2&dlat=%lf&dlon=%lf",@"APP名称", @"iosamap", @"我的位置",_locationTitle,_latitude, _longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:stringUrl]];

}]];


//百度

[alertController addAction:[UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"百度");
        
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
        
            NSMutableDictionary *baiduMapDic = [NSMutableDictionary dictionary];
            baiduMapDic[@"title"] = @"百度地图";
            NSString *stringUrl = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=北京&mode=driving&coord_type=gcj02",_latitude,_longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            baiduMapDic[@"url"] = stringUrl;
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:stringUrl]];
//            [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:stringUrl]];
        }

}]];


 //腾讯地图
    [alertController addAction:[UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSString *stringUrl =[[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&to=%@&tocoord=%lf,%lf&policy=1&referer=tengxun",_locationTitle,_latitude,_longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:stringUrl]];
        
    }]];


 [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertController animated:NO completion:nil];


以下来自:http://blog.csdn.net/ruglcc/article/details/52022592

转载请注明出处

苹果地图不需要,因为它是苹果地图啊,这样也好,能保证没有安装其他地图app,至少还有一个苹果地图,而且苹果地图在IOS9也做的越来越好了,本身API提供了一个跳转打开方法。

这里插入一个小细节,在IOS9之后,苹果进一步完善了安全机制,必须在plist里面设置url scheme白名单,不然无法打开对应的应用


  1. #pragma mark - 导航方法  
  2. - (NSArray *)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)endLocation

  1.  NSMutableArray *maps = [NSMutableArray array];  
  2.       
  3.     //苹果地图  
  4.     NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary];  
  5.     iosMapDic[@"title"] = @"苹果地图";  
  6.     [maps addObject:iosMapDic];   

  1. //谷歌地图
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {  
  2.         NSMutableDictionary *googleMapDic = [NSMutableDictionary dictionary];  
  3.         googleMapDic[@"title"] = @"谷歌地图";  
  4.         NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"导航测试",@"nav123456",endLocation.latitude, endLocation.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  5.         googleMapDic[@"url"] = urlString;  
  6.         [maps addObject:googleMapDic];  
  7.     } 
  1.     return maps;  


  1. #pragma mark LCActionSheetDelegate  
  2. -(void)actionSheet:(LCActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex  
  3. {  
  4.     if (buttonIndex != -1) {  
  5.         if (buttonIndex == 0) {  
  6.             [self navAppleMap];  
  7.             return;  
  8.         }  
  9.         NSDictionary *dic = self.maps[buttonIndex];  
  10.         NSString *urlString = dic[@"url"];  
  11.         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];  
  12.     }  
  13. }  
  14.   
  15. //苹果地图  
  16. - (void)navAppleMap  
  17. {  
  18.     CLLocationCoordinate2D gps = [JZLocationConverter bd09ToWgs84:self.destinationCoordinate2D];  
  19.       
  20.     MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];  
  21.     MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:gps addressDictionary:nil]];  
  22.     NSArray *items = @[currentLoc,toLocation];  
  23.     NSDictionary *dic = @{  
  24.                           MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,  
  25.                           MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),  
  26.                           MKLaunchOptionsShowsTrafficKey : @(YES)  
  27.                           };  
  28.       
  29.     [MKMapItem openMapsWithItems:items launchOptions:dic];  


转载请注明出处





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值