cool hit counter ios Jump to third party app to achieve navigation_Intefrankly

ios Jump to third party app to achieve navigation

To jump to a third-party app for navigation you first need to understand two issues 1.How to tell if a third-party navigation app is installed on your phone 2.How to implement a jump to a third party app

Question 1 For example, if you want to detect if you have the Baidu Maps app installed, it would be.

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]];

URL Scheme of 4 commonly used maps: 1.Apple comes with maps (no detection, so no need for URL Scheme) 2.Baidu map :baidumap:// 3.Gaode Map : iosamap:// 4.Google Maps : comgooglemaps://

Question 2 After iOS 9 we need to have a whitelist to do jumps


Specific implementation code

#import <MapKit/MapKit.h>

@implementation ThirdAppNavigationManager

+ (void)thirdAppNavigation:(NSString *)lat lng:(NSString *)lng
    NSMutableArray *maps = [NSMutableArray array];
    // Apple Native Maps- Apple's native map method is not the same as other
    NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary];
    iosMapDic[@"title"] = @" Apple Maps";
    [maps addObject:iosMapDic];
    // Baidu's map
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
        NSMutableDictionary *baiduMapDic = [NSMutableDictionary dictionary];
        baiduMapDic[@"title"] = @" Baidu's map";
        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{ My Location}}&destination=latlng:%@,%@|name= Beijing, capital of People's Republic of China&mode=driving&coord_type=gcj02",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        baiduMapDic[@"url"] = urlString;
        [maps addObject:baiduMapDic];
    // Gaode Map
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
        NSMutableDictionary *gaodeMapDic = [NSMutableDictionary dictionary];
        gaodeMapDic[@"title"] = @" Gaode Map";
        NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%@&lon=%@&dev=0&style=2",@" Navigation Features",@"nav123456",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        gaodeMapDic[@"url"] = urlString;
        [maps addObject:gaodeMapDic];
    // Google Maps
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
        NSMutableDictionary *googleMapDic = [NSMutableDictionary dictionary];
        googleMapDic[@"title"] = @" Google Maps";
        NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%@,%@&directionsmode=driving",@" Navigation test",@"nav123456",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        googleMapDic[@"url"] = urlString;
        [maps addObject:googleMapDic];
    // Tencent map
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
        NSMutableDictionary *qqMapDic = [NSMutableDictionary dictionary];
        qqMapDic[@"title"] = @" Tencent map";
        NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?from= My Location&type=drive&tocoord=%@,%@&to= finishing point&coord_type=1&policy=0",lat,lng] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        qqMapDic[@"url"] = urlString;
        [maps addObject:qqMapDic];
    // option
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@" Select Map" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    NSInteger index = maps.count;
    for (int i = 0; i < index; i++) {
        NSString * title = maps[i][@"title"];
        // Apple Native Maps Method
        if (i == 0) {
            UIAlertAction * action = [UIAlertAction actionWithTitle:title style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                [self navAppleMap:lat lng:lng];
            [alert addAction:action];
        UIAlertAction * action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString *urlString = maps[i][@"url"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {

        [alert addAction:action];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@" cancellation" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@" Clicked Cancel");
     [alert addAction:cancelAction];
    [[UIViewController getCurrentViewController] presentViewController:alert animated:YES completion:nil];

// Apple Maps
+ (void)navAppleMap:(NSString *)lat lng:(NSString *)lng
    // End point coordinates
    CLLocationCoordinate2D loc = CLLocationCoordinate2DMake(lat.doubleValue, lng.doubleValue);
    // User Location
    MKMapItem *currentLoc = [MKMapItem mapItemForCurrentLocation];
    // finish line
    MKMapItem *toLocation = [[MKMapItem alloc]initWithPlacemark:[[MKPlacemark alloc]initWithCoordinate:loc addressDictionary:nil] ];
    NSArray *items = @[currentLoc,toLocation];
    NSDictionary *dic = @{
                          MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving,
                          MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard),
                          MKLaunchOptionsShowsTrafficKey : @(YES)
    [MKMapItem openMapsWithItems:items launchOptions:dic];

1、Java multithreading core technology VI thread group and thread exception
2、Linux Server Performance Stress Test
3、Installing python on Linux
4、DryUnderstanding Neural Networks in One Article Series
5、iOSUIApplication Explained iOSUIApplication Explained

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送