How to launch another app from an iPhone app

后端 未结 3 2145
独厮守ぢ
独厮守ぢ 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条回答
  •  梦毁少年i
    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.

提交回复
热议问题