iOS app 打開第三方接口、撥打電話、打開地圖第三方app等

飛豬機(jī)票預(yù)訂:https://h5.m.taobao.com/trip/flight/search/index.html?spm=181.7474825.1998613473.1&ttid=&_preProjVer=0.1.69&_projVer=1.1.40

飛豬火車票/汽車票預(yù)訂:https://h5.m.taobao.com/trip/train/search/index.html?_projVer=0.5.62

美團(tuán)購買/搜索:http://i.meituan.com/s/liupanshui- 加上要搜索商品的名稱

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

中國天氣網(wǎng):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,這種方法,撥打完電話回不到原來的應(yīng)用,會停留在通訊錄里,而且是直接撥打,不彈出提示

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

轉(zhuǎn)載請注明出處

蘋果地圖不需要,因?yàn)樗翘O果地圖啊,這樣也好,能保證沒有安裝其他地圖app,至少還有一個蘋果地圖,而且蘋果地圖在IOS9也做的越來越好了,本身API提供了一個跳轉(zhuǎn)打開方法。

這里插入一個小細(xì)節(jié),在IOS9之后,蘋果進(jìn)一步完善了安全機(jī)制,必須在plist里面設(shè)置url scheme白名單,不然無法打開對應(yīng)的應(yīng)用

#pragma?mark?-?導(dǎo)航方法

-?(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",@"導(dǎo)航測試",@"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];

}

版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容