以编程方式检测应用程序是否安装在 iPhone 上 [英] Detecting programmatically whether an app is installed on iPhone

查看:28
本文介绍了以编程方式检测应用程序是否安装在 iPhone 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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

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.

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

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

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

适用于每个场景的所有代码示例

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.

这篇关于以编程方式检测应用程序是否安装在 iPhone 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆