Detecting programmatically whether an app is installed on iPhone

Viewed 31426

I am in this situation where I have to display a button which says "Open myApp" (if myApp is installed on the device) or it says "Download myApp" (if myApp is not installed on the device) in an iphone app. To do this, I need to detect whether an app (with a known custom URL) has been installed on the device. How can I do this? Thanks in advance.

5 Answers

For those using canOpenURL it is always safe to migrate from this to openURL:options:completionHandler:

NSString *urlString = @"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
        if (!success) {
            [[UIApplication sharedApplication] openURL:appStoreUrl options:@{} completionHandler:nil];
        }
}];

because that doesn't require you to declare the scheme ahead of time.

canOpenURL which is deprecated already has some odd limitations because Twitter used it to detect hundreds of apps long ago.

Related