在 iOS 9 和 10 上检查已安装的应用程序 [英] Check for installed apps on iOS 9 and 10

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

问题描述

我正在尝试检查用户是否安装了几个应用程序.我需要它在 ios9 和 ios 10 上工作.我首先在 ios9 上进行测试,即使应用程序通过,schemeAvailable func 也返回 true未安装在设备上.

I am trying to check if a user has installed a couple of apps. I need it to work on ios9 and ios 10. I am testing on ios9 first and the schemeAvailable func is returning true even though the app passed is not installed on the device.

func schemeAvailable(scheme: String) -> Bool {
   if let url = URL(string: scheme) {
       return UIApplication.shared.canOpenURL(url)
   }
   return false
}

我已将以下内容添加到我的 info.plist,即我将检查的应用程序已安装:

I have added the following to my info.plist i.e. the apps I will check are installed:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>app1</string>
<string>app2</string>
</array>

在我项目的信息选项卡中,我添加了 2 种 url 类型并为每个类型插入了标识符和 url 方案.

and in my project's info tab, I have added 2 url types and inserted the identifier and url scheme for each.

推荐答案

听起来您没有正确注册所有内容.您的 App1 和 App2 都需要 URL 标识符和方案,并且您的想要启动 App1 和 App2"的应用程序必须定义 LSApplicationQueriesSchemes.

It sounds like you do NOT have all registrations correct. Your App1 and App2 each need URL Identifiers and Schemes, and your app that "wants to launch App1 and App2" must have LSApplicationQueriesSchemes defined.

例如

这是在App1"中

这是在App2"中

这是在LauncherApp"中

This is in "LauncherApp"

然后,在LauncherApp"中,我可以:

Then, in "LauncherApp" I can do:

    let s = "DMCApp1://TestMe"
    let customURL: URL = URL(string: s)!

    if UIApplication.shared.canOpenURL(customURL) {
        print("YES - I can open App1 !!!")
        UIApplication.shared.open(customURL, options: [:], completionHandler: nil)
    } else {
        print("NO - App1 is not available.")
    }

这篇关于在 iOS 9 和 10 上检查已安装的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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