How to Programmatically check and open an existing app in iOS 8?

后端 未结 6 2015
执笔经年
执笔经年 2021-02-08 04:14

I want to check whether an app is present in my iphone or not. If it is present I want to launch it else open the App Store link of the app.

Please suggest the required

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 05:01

    You can check whether app is available or not using URL scheme iOS feature and then open iTunes url.Try with following code for your solution:

    First set URL scheme "testapp" in your itunes app and then use following code in other app from where you want to open your app :

    -(IBAction) openApp:(id)sender {
    
        // Opens the app if installed, otherwise displays an error
        UIApplication *yourApplication = [UIApplication sharedApplication];
        NSString *URLEncodedText = [self.textBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *ourPath = [@"testapp://" stringByAppendingString:URLEncodedText];
        NSURL *ourURL = [NSURL URLWithString:ourPath];
        if ([yourApplication canOpenURL:ourURL]) {
            [yourApplication openURL:ourURL];
        }
        else {
            //The App is not installed. It must be installed from iTunes code.
            NSString *iTunesLink = @"//Your itunes Url";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
        }
    
    }
    

提交回复
热议问题