Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch another app from an iPhone app

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.

like image 476
Ranjan Sahu Avatar asked Oct 20 '12 11:10

Ranjan Sahu


People also ask

Can you run two of the same app on iPhone?

Tap and hold on the app, then drag it to the left edge of the screen and drop it onto a Home Screen. Repeat this process as many times as you like to create as many duplicates as you need.

How do I open multiple instances of an iPhone app?

It is not possible to install two instances of the same app on iOS. Some services accessed by an app also have a web site with equivalent or at least similar functionality.


2 Answers

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.

like image 125
st.derrick Avatar answered Sep 19 '22 02:09

st.derrick


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.

like image 44
bs7 Avatar answered Sep 20 '22 02:09

bs7