“ canOpenURL”的行为很奇怪...还是我吗?

时间:2018-07-15 13:30:21

标签: swift xcode swift4 xcode9

我觉得很奇怪,尽管canOpenURL(myURL)为false,而open(myURL)完全重定向到了我想要的应用程序。我在这里做什么错了?

override func viewDidAppear(_ animated: Bool) {
    let instagramUrl = URL(string: "instagram://app")!
    print(UIApplication.shared.canOpenURL(instagramUrl))    // false
    if UIApplication.shared.canOpenURL(instagramUrl) {
        UIApplication.shared.open(instagramUrl, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.open(URL(string: "http://instagram.com")!, options: [:], completionHandler: nil)    // Instagram successfully launched???
        // UIApplication.shared.open(instagramUrl, options: [:], completionHandler: nil)        // This works too
        print("Open failed.")    // Open failed.
    }
}

控制台:

-canOpenURL:URL:“ instagram:// app”失败-错误:“此应用不允许查询方案instagram”

[MC] systemgroup.com.apple.configurationprofiles路径的系统组容器为/private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

[MC]从公共有效用户设置中读取。

我的Info.plist如下

enter image description here

1 个答案:

答案 0 :(得分:2)

您必须将URL 方案包括在LSApplicationQueriesSchemes中,而不是URL本身。

因此,您只需要一个值为LSApplicationQueriesSchemes一个项目即可使用它,而不是当前instagram中的所有项目。