以编程方式检测iPhone上是否安装了应用程序

时间:2010-09-27 23:46:10

标签: iphone url installed-applications

我遇到这种情况,我必须显示一个按钮,上面写着“打开myApp”(如果设备上安装了myApp),或者在iPhone上显示“下载myApp”(如果myApp没有安装在设备上)应用程序。为此,我需要检测设备上是否安装了应用程序(具有已知的自定义URL)。我怎样才能做到这一点?提前谢谢。

5 个答案:

答案 0 :(得分:33)

2014年1月8日更新 - 您可以做的3件事

我实际上不得不再次为客户做这件事。他们希望用户能够从主应用程序中打开他们的第二个应用程序(如果已安装)。

这是我的发现。使用canOpenURL方法检查是否安装了应用或/,然后使用openURL方法

  1. 打开iOS设备上安装的应用程序
  2. 将用户带到应用商店,直接将他们指向应用/您的开发者应用列表
  3. 将他们带到网站
  4. 每个方案可用的所有代码示例

    //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"]];
    
        } 
    }
    

    选择一个选项,我只是选择了你。选择一个符合您要求的产品。 在我的情况下,我不得不在程序的不同区域使用所有三个选项。

答案 1 :(得分:20)

如果您的应用的网址方案是“myapp:”,那么

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

(需要iOS 3.0。)

答案 2 :(得分:5)

检查应用是否已在设备中安装

1)在info.plist中添加LSApplicationQueriesSchemes如下例

enter image description here

2)和网址类型

enter image description here

3)现在检查app是否安装

- (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"]];
    }
}

答案 3 :(得分:0)

您可以在需要此应用程序嗅探的任何页面的头部添加一个简单的元标记。

欲了解更多信息,请访问:

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

答案 4 :(得分:0)

对于使用canOpenURL的用户而言,始终可以安全地从其中迁移到runas /user:Administrator "your command"

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]; } }]; 已经有一些奇怪的限制,因为Twitter很久以前就使用它来检测数百种应用。

相关问题