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

Ama*_*rsh 15 iphone url installed-applications

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

Pav*_*van 33

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

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

这是我的发现.使用该canOpenURL方法检查是否安装了应用程序或/然后使用该openURL方法

  1. 打开iOS设备上安装的应用程序
  2. 将用户带到应用商店,直接将他们指向应用/您的开发者应用列表
  3. 把他们带到一个网站

每个方案可用的所有代码示例

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

    } 
}
Run Code Online (Sandbox Code Playgroud)

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


小智 20

如果您的应用的URL方案是"myapp:",那么

BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp:"]];
Run Code Online (Sandbox Code Playgroud)

(需要iOS 3.0.)


Har*_*kar 5

要检查应用程序是否安装在设备中

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

在此输入图像描述

2)和URL类型

在此输入图像描述

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"]];
    }
}
Run Code Online (Sandbox Code Playgroud)