Detecting programmatically whether an app is installed on iPhone

僤鯓⒐⒋嵵緔 提交于 2019-11-26 18:47:30

UPDATED 8th January 2014 - 3 things you can do

I actually had to do this for a client again. They wanted users to be able to open their second app from the main app if it had been installed.

This is my finding. Use the canOpenURL method to check if an app is installed or/and then use the openURL method to

  1. Open the application installed on the iOS device
  2. Take the user to the app store directly pointing them to the app/your list of developer apps
  3. Take them to a website instead

All code samples available for each scenario

//Find out if the application has been installed on the iOS device
- (BOOL)isMyAppInstalled { 
    return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"nameOfMyApp:"]]; 
} 

- (IBAction)openOrDownloadApp { 
    //This will return true if the app is installed on the iOS device
    if ([self myAppIsInstalled]){
        //Opens the application
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"nameOfMyApp:"]]; 
    } 
    else { //App is not installed so do one of following:

        //1. Take the user to the apple store so they can download the app
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/nameOfMyApp"]]; 

        //OR

        //2. Take the user to a list of applications from a developer
        //or company exclude all punctuation and space characters. 
        //for example 'Pavan's Apps'
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/PavansApps"]];

        //OR

        //3. Take your users to a website instead, with maybe instructions/information
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];

    } 
}

Choose one option, I've just spoiled you with choice. Choose one that fits your requirements. In my case I had to use all three options in different areas of the program.

Mark T.

If the URL scheme for your app is "myapp:", then

BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp:"]];

(Requires iOS 3.0.)

To check app is install in device or not

1) In info.plist add LSApplicationQueriesSchemes as below example

2) and in URL Types

3) Now to check app is install or not

- (IBAction)openAppPressed:(UIButton *)sender {
    NSString *urlString = @"XYZAPP://";
    NSURL *url = [NSURL URLWithString:urlString];

    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }
    else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes link for download app"]];
    }
}

You can add a simple meta tag in the head of any page that needs this app-sniffing.

For more info, go here:

http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!