How to check programmatically if an App is installed?

Viewed 50040

I am developing an iPhone application which will install few third party applications in an enterprise. I have the information about the bundle IDs. Is there a way to check if the application is already installed, using some system APIs? Currently the application gets installed again, overwriting the current installation. I need to prevent this some how. (Apple's AppStore application disables the installation option if the app is already installed.)

6 Answers

Swift 3.1, Swift 3.2, Swift 4

if let urlFromStr = URL(string: "fb://") {
    if UIApplication.shared.canOpenURL(urlFromStr) {
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(urlFromStr, options: [:], completionHandler: nil)
        } else {
            UIApplication.shared.openURL(urlFromStr)
        }
    }
}

Add these in Info.plist :

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb</string>
</array>

iOS 9 and newer update:

Because of some security changes Apple made starting in iOS 9, in addition to canOpenURL mentioned in other answers, you also need to add an LSApplicationQueriesSchemes array with strings in info.plist. See screenshot for an example using Twitter.

info.plist LSApplicationQueriesSchemes array

If you wanted to add Facebook, you would just add another item in the array with a string value of "fb".

Related