【问题标题】:canOpenURL: failed for URL: "instagram://app" - error: "This app is not allowed to query for scheme instagram"canOpenURL:URL 失败:“instagram://app” - 错误:“此应用不允许查询方案 instagram”
【发布时间】:2017-05-15 09:30:58
【问题描述】:

这是我使用的代码:

let instagramURL = NSURL(string: "instagram://app")
if UIApplication.shared.canOpenURL(instagramURL! as URL) {
  //Code
} else {
  //Showing message "Please install the Instagram application"
}

我进入 if 循环失败了。

我收到此错误:

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

我还在我的设备中使用 Instagram 登录。

【问题讨论】:

  • UIApplication.shared.canOpenURL 检查 your 应用是否可以打开 URL。该错误表明您不允许检查 your 应用是否可以打开 Instragram URL(因为您可以编写恶意代码来拦截用于其他应用的 URL)。你想完成什么?

标签: ios iphone swift


【解决方案1】:

右键单击您的 plist 文件并将其作为源代码打开。然后复制并粘贴以下代码:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram</string>
</array>

注意:您必须记住一件事,它不适用于模拟器。为此,您需要一个真实的设备。

【讨论】:

  • 感谢您的注意,否则我会花几个小时来调试我的代码 xD
【解决方案2】:

打开您的 plist 作为源代码并粘贴以下代码:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram</string>
</array>

【讨论】:

    【解决方案3】:

    问题是您没有在 info.plist 文件中注册 URL 方案。

    请添加此 LSApplicationQueriesSchemes 并将 instagram 添加到您的 info.plist 中,它将起作用。

    【讨论】:

    • 截至 2019 年:字符串必须是 instagram
    【解决方案4】:

    对于那些尝试使用自定义 URL 方案打开应用程序的人(假设应用程序 FirstApp 打开 SecondApp):

    • 在 FirstApp 中,将带有 URL Scheme 的 LSApplicationQueriesSchemes 添加到 Info.plist,如下所示:

    • 在 SecondApp 中,在 URL 类型中注册新的 URL 方案,如下所示:

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 1970-01-01
      • 2016-01-26
      • 2015-12-20
      • 2015-12-28
      • 2019-01-28
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多