10

I am working on a map application in my iPhone app.

I have a button go.

When the user clicks this button in this method I want to check if user has installed the waze application on his iphone. If yes then navigate to waze application otherwise open iPhone's default map app.

3 Answers 3

21

Try to do this way :

NSString *wazeAppURL = @"waze://";
NSString *mapsAppURL = @"maps://";

BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]];

NSString *url = canOpenURL ? wazeAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Here, canOpenURL allows you to test if the Waze app is installed on your iPhone. if iPhone can open the url waze:// it means you already have the app and it will launch it. Otherwise it will launch the default Maps app. Safari won't be called.

3
  • hi if we open URL the control will go to safari and where i will get URL the app-store URL or any thing else.my application point is from my app the user can navigate through waze while click on the button if waze application is installed in users phone other wise the default app.how can i check the waze app is installed in user's iPhone.can you please elaborate all these things. Oct 22, 2012 at 6:14
  • @bs7 How can we get list of all routing app present in iphone, like In my phone I have google map, apple map & waze. How can I get that ? May 16, 2016 at 11:13
  • Is there a way to get response when the external app is closed? Something like onActivityResult on Android? May 9, 2019 at 14:41
5

To open an app you need to call

BOOL canOpenURL = [[UIApplication sharedApplication] 
                       canOpenURL:[NSURL URLWithString:@"app://"]];
if ( canOpenUrl ) [[UIApplication sharedApplication] 
                       openURL:[NSURL URLWithString:url]];

To find all the url, go to this page: http://handleopenurl.com/

For waze in particular, http://handleopenurl.com/scheme/waze

hope this helps.

0
1

Note that on iOS you can also navigate to Google Maps -- and pass along the query string or geopoint. Here's one example of navigating to a specific geopoint:

if (self.mapView.userLocation.location) {
    NSString *urlAsString = [NSString stringWithFormat:@"comgooglemaps://?q=%f,%f", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlAsString]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAsString]];
    }
} 

Just a suggestion to enhance the user experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.