part1:URI方式跳轉應用外地圖類應用導航ios
功能:首先獲取該設備支持應用外地圖類應用的列表->傳入該應用的對應的接口參數,實現跳轉->(若支持回跳轉,在應用類傳入相應的接口參數跳轉回來)。git
實現:1.首先獲取支持跳轉的地圖應用列表:api
if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]){ //蘋果地圖... } if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]){ //百度地圖... } if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){ //高德地圖... }
2.查找各個跳轉應用的api接口要求和協議格式,如高德:app
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"選擇地圖" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }]; [alert addAction:action];}
3.這個是跳轉到地圖類應用的導航類功能,所以部分應用如高德和google支持跳轉後,回跳回原應用。通常都是經過一開始跳轉的時候傳入的接口來判斷結束導航後跳轉該原應用而實現跳轉。google