How to launch another app from an iPhone app

后端 未结 3 2130
独厮守ぢ
独厮守ぢ 2020-12-31 15:19

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

相关标签:
3条回答
  • 2020-12-31 15:38

    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 讨论(0)
  • 2020-12-31 15:56

    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.

    0 讨论(0)
  • 2020-12-31 15:58

    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.

    0 讨论(0)
提交回复
热议问题