iOS 支持第三方导航

iOS support 3rd party navigation

在 iOS 8(我不记得也可能是 7)中,您可以设置导航的默认应用程序。我目前正在实现一个按钮,允许用户打开 Apple 地图并通过以下方式获取前往某个位置的路线:

- (IBAction)getDirections:(id)sender {

CLLocationCoordinate2D endingCoord = storeLocation;
MKPlacemark *endLocation = [[MKPlacemark alloc] initWithCoordinate:endingCoord addressDictionary:nil];
MKMapItem *endingItem = [[MKMapItem alloc] initWithPlacemark:endLocation];
endingItem.name = @"Cubes Pizza Sunway";

NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init];
[launchOptions setObject:MKLaunchOptionsDirectionsModeDriving forKey:MKLaunchOptionsDirectionsModeKey];

[endingItem openInMapsWithLaunchOptions:launchOptions];

}

效果很好,启动效果符合我的预期。但是,如果用户安装了 Google 地图怎么办?苹果会自动给用户一个选项吗?或者我是否需要实施 activity sheet 并检测所有导航应用程序,然后找出每个导航应用程序的 URL 模式?)

我将如何实施这样的事情?

这是同一个问题:iOS - run 3rd party navigation app from code但是已经有一年了,想知道这个功能是否由 APPLE 实现,如果不是,如何实现检查是否安装了应用等。

Google Maps has a URL scheme that you can use to launch the app. Here is how you request directions。如他们的页面所述,您可以通过以下方式检查是否安装了 Google 地图应用程序:

UIApplication.sharedApplication().canOpenURL(NSURL(string: "comgooglemaps://")!)

您还需要将 comgooglemaps 添加到 Info.plist 中的 LSApplicationQueriesSchemes 词典中,以便能够在 iOS 上使用 canOpenURL: 方法9,如this blog post.

所述

我相信你想的 "default navigation app" 实际上是 a way for the user to manually switch other apps once they're in the built-in Maps app