您可能认为这是一个重复的问题,但事实并非如此,我完全了解 SO 上关于 canOpenURL
及其在 iOS 9 上的警告的所有答案,但这是我的问题:
我正在尝试检查我的设备上是否安装了特定的应用程序(均由我开发)。
我已将 AppA
上的方案声明为:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.my.company.id</string>
<key>CFBundleURLSchemes</key>
<array>
<string>XYZ</string>
</array>
</dict>
</array>
在另一个应用程序 AppB
上,我在 info.plist 中添加了:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>XYZ</string>
</array>
现在,在 AppB
中,我试图找出我是否像这样安装了 AppA
:
internal static let appAScheme = "XYZ://"
static func AppAInstalled() -> Bool {
let appAURL = NSURL(string: appAScheme)
return UIApplication.sharedApplication().canOpenURL(appAURL!)
}
它总是返回
-canOpenURL: failed for URL: "XYZ://" - error: "This app is not allowed to query for scheme XYZ"
但是,如果我尝试从 AppB
打开 AppA
,它会正常工作!
// Works alright
UIApplication.sharedApplication().openURL(appAURL!)
我不明白这是为什么!
最佳答案
我已经找到了我自己问题的解决方案。我在这里回答它,而不是仅仅删除我的问题,因为它有一天可能会对某人有所帮助。
这里的问题是我正在尝试为其他开发人员开发一个框架,我有一个测试应用程序用于检查我的框架是否一切正常。我在框架目标中设置 LSApplicationQueriesSchemes
值,而不是实际的测试应用程序。所以:
You need to set the whitelist values in your app target's info.plist
关于swift - 不允许此应用查询方案 XYZ ://,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34523816/