【发布时间】:2020-04-09 17:03:10
【问题描述】:
请帮忙!为什么尽管将方案包含在 LSApplicationQueriesSchemes 中,但仍然不允许查询方案?
我的班级:
class LearningBotScreen: UIViewController {
@IBAction func googleAssistantOpenButtonPressed(_ sender: Any) {
let googleAssistantUrl = URL(string:"youtube://")!
if UIApplication.shared.canOpenURL(googleAssistantUrl){
print("opening");
UIApplication.shared.open(googleAssistantUrl)
/*UIApplication.shared.open(googleAssistantUrl!, options:[:], completionHandler: nil)*/
}
else{
print("download app")
UIApplication.shared.open(URL(string: "http://apps.apple.com/sg/app/id1220976145")!, options: [:], completionHandler: nil)
}
}
我的info.plist:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0">
<dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
<string>youtube</string>
</array>
<key>LSApplicationCategoryType</key> <string></string>
<key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key> <string>6.0</string>
<key>CFBundleName</key> <string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key> <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key> <string>1.0</string>
<key>CFBundleVersion</key> <string>1</string> </dict> </plist>
2019-12-17 15:58:08.426142+0800 drmorpheus[1000:203271] -canOpenURL: URL 失败:“youtube://” - 错误:“此应用不允许 查询方案youtube”下载应用
【问题讨论】:
-
这是你的 UI 测试 info.plist。您应用的 info.plist 是什么样的?
-
您好,非常感谢您的回答!接得好!我的应用程序的 info.plist 中确实缺少它。我添加了它,但它似乎仍然无法正常工作 >
-
嗯,这真的很奇怪。我不太确定为什么它仍然给你这个错误。也许尝试从您的设备中删除您的应用程序并重新安装它?显然
canOpenURL只能被你的应用调用50次,根据docs:“如果你的应用链接到iOS的早期版本但运行在iOS 9.0或更高版本,你可以调用这个方法最多50次次。达到该限制后,后续调用始终返回 false。如果用户重新安装或升级应用程序,iOS 会重置限制。" -
谢谢!!我设法修复它。我认为这与您告诉我的应用程序中的 info.plist 有关:D 我重建了项目并且它有效!