简体   繁体   中英

iOS support 3rd party navigation

In iOS 8 (maybe 7 too I can't recall) you can set default applications for navigation. I am currently implementing a button that allows a user to open up Apple Maps and get directions to a location the following way:

- (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];

}

This works great and launches how I'd expect. However, what if the user has Google Maps installed? Will Apple automatically give the user an option? Or do I need to implement an activity sheet and detect all the navigation apps and then figure out the URL schemas for each one?)

How would I go about implementing such a thing?

This is the same question: iOS - run 3rd party navigation app from code but it's a year old and wanted to know if this feature was implemented by APPLE and if not how to implement checking if app is installed etc.

Google Maps has a URL scheme that you can use to launch the app. Here is how you request directions . As described on their page you can check if the Google Maps app is installed via:

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

You'll also need to add comgooglemaps to the LSApplicationQueriesSchemes dictionary in your Info.plist to be able to use the canOpenURL: method on iOS 9, as described in this blog post .

I believe the "default navigation app" you're thinking of is actually a way for the user to manually switch other apps once they're in the built-in Maps app .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM