Detect if iOS app is installed from within another

2020-05-03 01:02发布

问题:

I have a button on my iOS app that will launch a third party app via deeplinking, but if said app is not installed, the button will not do anything.

How can I check if the app is installed first, if not, prompt the user to download it?

Button code:

@IBAction func didTapEdmodo(sender: AnyObject) {
    UIApplication.sharedApplication().openURL(NSURL(string: "edmodo://")!)
}

回答1:

You can call canOpenURL: to check. Note that you need to declare the URL scheme in your info.plist before you can make the request. This is done using the LSApplicationQueriesSchemes key.