如何以编程方式检查是否安装了应用程序?

att*_*sof 39 iphone cocoa-touch objective-c ipad ios4

我正在开发一个iPhone应用程序,它将在企业中安装很少的第三方应用程序.我有关于捆绑ID的信息.有没有办法使用某些系统API检查应用程序是否已安装?目前,应用程序再次安装,覆盖当前安装.我需要防止这种情况.(如果已安装该应用程序,Apple的AppStore应用程序将禁用安装选项.)

mvd*_*vds 63

我认为这不可能直接,但如果应用程序注册uri方案,你可以测试.

例如fb://,对于facebook app,URI方案.您可以在应用的info.plist中注册.[UIApplication canOpenURL:url]会告诉你某个网址是否会打开.因此测试if是否fb://会打开,将表明已经安装了一个已注册的应用程序fb://- 这是对facebook应用程序的一个很好的提示.

// check whether facebook is (likely to be) installed or not
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
    // Safe to launch the facebook app
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/200538917420"]];
}
Run Code Online (Sandbox Code Playgroud)


AlB*_*ebe 31

这是测试facebook应用程序是否已安装的示例

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
    // Facebook app is installed
}
Run Code Online (Sandbox Code Playgroud)


sud*_*all 24

对于试图使用iOS 9/Swift 2执行此操作的任何人:

首先,您需要通过在Info.plist文件中添加以下内容来将网址"列入白名单" (安全功能 - 请参阅Leo Natan的回答):

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb</string>
</array>
Run Code Online (Sandbox Code Playgroud)

之后,您可以询问该应用程序是否可用并具有注册方案:

guard UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb://")!) else {
    NSLog("No Facebook?  You're a better man than I am, Charlie Brown.")
    return
}
Run Code Online (Sandbox Code Playgroud)


Vin*_*App 7

斯威夫特 3.1、斯威夫特 3.2、斯威夫特 4

if let urlFromStr = URL(string: "fb://") {
    if UIApplication.shared.canOpenURL(urlFromStr) {
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(urlFromStr, options: [:], completionHandler: nil)
        } else {
            UIApplication.shared.openURL(urlFromStr)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在 Info.plist 中添加这些:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fb</string>
</array>
Run Code Online (Sandbox Code Playgroud)