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

标签 iphone url installed-applications

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

最佳答案

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

    } 
}

选择一个选项,我只是用选择宠坏了你。选择一款适合您的要求的产品。 就我而言,我必须在程序的不同区域使用所有三个选项。

关于iphone - 以编程方式检测 iPhone 上是否安装了应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3808691/

相关文章:

ios - 在 Xcode 中针对不同屏幕尺寸优化应用程序的最简单方法?

iphone - 关闭应用内购买?

iphone - 不显示多个动态大小的标签

java - 使用 Java 检索 URL 中的参数

url - 使用 URL 重定向站点阻止 Telegram 链接预览

ios - 将参数传递给 addTarget :action:forControlEvents

Java网络应用程序: prevent a slash from being added to the path?

android - 如何获取所有应用程序(包括系统应用程序)的列表?

c++ - MsiEnumProductsEx 不工作

android - 如何获取已安装应用的电池使用详情?