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=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"186xxxx6979"];

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

2,这种方法,打完电话后还会回到原来的程序,也会弹出提示,推荐这种

NSMutableString*

str=[[NSMutableStringalloc]initWithFormat:@"tel:%@",@"186xxxx6979"];UIWebView* callWebview = [[UIWebViewalloc]init];

[callWebviewloadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:str]]];

[self.viewaddSubview:callWebview];

3,这种方法也会回去到原来的程序里(注意这里的telprompt),也会弹出提示

NSMutableString*

str=[[NSMutableStringalloc]initWithFormat:@"telprompt://%@",@"186xxxx6979"];//NSLog(@"str======%@",str);[[UIApplicationsharedApplication]openURL:[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白名单,不然无法打开对应的应用

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

#pragma mark - 导航方法

- (NSArray*)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)endLocation

NSMutableArray*maps = [NSMutableArrayarray];

//苹果地图

NSMutableDictionary*iosMapDic = [NSMutableDictionarydictionary];

iosMapDic[@"title"] =@"苹果地图";

[mapsaddObject:iosMapDic];

//谷歌地图if([[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"comgooglemaps://"]]) {

NSMutableDictionary*googleMapDic = [NSMutableDictionarydictionary];

googleMapDic[@"title"] =@"谷歌地图";

NSString*urlString = [[NSStringstringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",@"导航测试",@"nav123456",endLocation.latitude, endLocation.longitude]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

googleMapDic[@"url"] = urlString;

[mapsaddObject:googleMapDic];

}

returnmaps;

}

#pragma mark LCActionSheetDelegate

-(void)actionSheet:(LCActionSheet*)actionSheetdidClickedButtonAtIndex:(NSInteger)buttonIndex

{

if(buttonIndex != -1) {

if(buttonIndex ==0) {

[selfnavAppleMap];

return;

}

NSDictionary*dic =self.maps[buttonIndex];

NSString*urlString = dic[@"url"];

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:urlString]];

}

}

//苹果地图

- (void)navAppleMap

{

CLLocationCoordinate2D gps = [JZLocationConverterbd09ToWgs84:self.destinationCoordinate2D];

MKMapItem*currentLoc = [MKMapItemmapItemForCurrentLocation];

MKMapItem*toLocation = [[MKMapItemalloc]initWithPlacemark:[[MKPlacemarkalloc]initWithCoordinate:gpsaddressDictionary:nil]];

NSArray*items = @[currentLoc,toLocation];

NSDictionary*dic = @{

MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,

MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),

MKLaunchOptionsShowsTrafficKey : @(YES)

};

[MKMapItemopenMapsWithItems:itemslaunchOptions:dic];

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(iOS app 打开第三方接口、拨打电话、打开地图第三方app等)