Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios canOpenURL:对于URL:“失败”;instagram://app" - 错误:";此应用程序不允许查询scheme instagram“;_Ios_Iphone_Swift - Fatal编程技术网

Ios canOpenURL:对于URL:“失败”;instagram://app" - 错误:";此应用程序不允许查询scheme instagram“;

Ios canOpenURL:对于URL:“失败”;instagram://app" - 错误:";此应用程序不允许查询scheme instagram“;,ios,iphone,swift,Ios,Iphone,Swift,这是我使用的代码: 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

这是我使用的代码:

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-错误:“不允许此应用查询scheme instagram”


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

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

请将此LSApplicationQueriesSchemes和instagram添加到您的info.plist中,它将正常工作。

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

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

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

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

注意:您必须记住一件事,它在模拟器上不起作用。为此,您需要一台真正的设备。

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

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

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

UIApplication.shared.canOpenURL
检查应用程序是否可以打开URL。该错误表示您不允许检查您的应用程序是否可以打开Instragram URL(因为您可能会编写恶意代码来拦截其他应用程序的URL)。你想完成什么?谢谢你的提示,否则我会花几个小时调试2019年的xDas代码:字符串需要是instagram