Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 9未使用URL方案打开Instagram应用程序_Ios_Ios9 - Fatal编程技术网

iOS 9未使用URL方案打开Instagram应用程序

iOS 9未使用URL方案打开Instagram应用程序,ios,ios9,Ios,Ios9,以下URL在iOS 8.3及更低版本上打开,但在iOS 9和iOS 9上不起作用 let instagramURL = NSURL(string: "instagram://app") 为什么URL无法打开?这是iOS 9的一项新安全功能。关注更多信息 使用SDK 9构建的任何应用程序都需要在其plist文件中提供一个LSApplicationQueriesSchemes条目,声明它试图查询的方案 <key>LSApplicationQueriesSchemes</key&g

以下URL在iOS 8.3及更低版本上打开,但在iOS 9和iOS 9上不起作用

let instagramURL = NSURL(string: "instagram://app")

为什么URL无法打开?

这是iOS 9的一项新安全功能。关注更多信息

使用SDK 9构建的任何应用程序都需要在其plist文件中提供一个
LSApplicationQueriesSchemes
条目,声明它试图查询的方案

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>urlscheme</string>
 <string>urlscheme2</string>
 <string>urlscheme3</string>
 <string>urlscheme4</string>
</array> 
LSApplicationQueriesSchemes
URL方案
urlscheme2
urlscheme3
urlscheme4

iOS 9对URL方案的处理做了一个小小的改变。您必须在您的
Info.plist
中使用
lsapplicationqueryschemes
键将应用程序调用的url列入白名单

请看这里的帖子:

主要结论是:

如果您对不在白名单中的URL调用“canOpenURL”方法,它将返回“否”,即使安装了已注册以处理此方案的应用程序。将出现“此应用程序不允许查询方案xxx”系统日志条目

如果对不在白名单中的URL调用“openURL”方法,它将以静默方式失败。将出现“此应用程序不允许查询方案xxx”系统日志条目


作者还推测这是操作系统的一个bug,苹果将在后续版本中修复这个bug。

假设有两个应用程序TestA和TestB。TestB想查询是否安装了TestA。“TestA”在其info.plist文件中定义了以下URL方案:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>testA</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>
但这通常会在iOS9中返回NO,因为需要将“TestA”添加到TestB的info.plist文件中的LSApplicationQueriesSchemes条目中。通过将以下代码添加到TestB的info.plist文件中来完成此操作:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>testA</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>
LSApplicationQueriesSchemes

似乎没有人解决过如何使用嵌入参数指定URL的问题。任何包含参数的URL都无法在LSApplicationQueriesSchemes中指定特定URL。例如,假设我有一个传递发件人电子邮件地址的电子邮件应用程序:

myemail://mailto?bob@gmail.com

在iOS9中使其工作的唯一方法似乎是删除任何参数。

来自第703次会议WWDC 2015:

在为iOS 9构建应用程序时,您可以继续使用URL方案 如果要调用URL方案,现在需要在中声明它们 你的应用程序Info.plist。有一个新键,
LSApplicationQueriesSchemes
, 在这里,您需要添加您想要的方案列表 卡诺佩恩


如上所述,您需要在信息列表中添加一个键,以下是大多数社交网络的列表

<key>LSApplicationQueriesSchemes</key>
    <array>
     <string>fb</string>
     <string>fbapi</string>
     <string>fbauth2</string>
     <string>fbshareextension</string>
     <string>fb-messenger-api</string>
     <string>twitter</string>
     <string>viber</string>
     <string>whatsapp</string>
     <string>wechat</string>
     <string>line</string>
     <string>instagram</string>
     <string> instagram-stories</string>
     <string>kakaotalk</string>
     <string>mqq</string>
     <string>vk</string>
     <string>comgooglemaps</string>
     <string>googlephotos</string>
     <string>ha</string>
     <string>yammer</string>
    </array>
LSApplicationQueriesSchemes
食品饮料
fbapi
fbauth2
fbshareextension
fb messenger api
啁啾
毒蛇
WhatsApp
微信
线
instagram
instagram故事
卡考塔克
mqq
vk
谷歌地图
谷歌照片
哈
唠叨
*
前3个匹配Facebook(FBSDK 4.6):fbapi、fbauth2、fbshareextension。“Ha”用于snapchat

即使使用@Matthieu-answer,通过共享对话框进行Facebook共享也会失败(对于其他社交URL,这是100%正确的)。我不得不添加一组从Facebook SDK中反转过来的URL

<array>
        <string>fbapi</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
        <string>fb-messenger-api</string>
        <string>twitter</string>
        <string>whatsapp</string>
        <string>wechat</string>
        <string>line</string>
        <string>instagram</string>
        <string>kakaotalk</string>
        <string>mqq</string>
        <string>vk</string>
        <string>comgooglemaps</string>
        <string>fbapi20130214</string>                                                    
        <string>fbapi20130410</string>                                                     
        <string>fbapi20130702</string>                                                    
        <string>fbapi20131010</string>                                                    
        <string>fbapi20131219</string>                                                    
        <string>fbapi20140410</string>                                                     
        <string>fbapi20140116</string>                                                     
        <string>fbapi20150313</string>                                                     
        <string>fbapi20150629</string>
    </array>

fbapi
fbauth2
fbshareextension
fb messenger api
啁啾
WhatsApp
微信
线
instagram
卡考塔克
mqq
vk
谷歌地图
fbapi20130214
fbapi20130410
fbapi20130702
fbapi20131010
fbapi20131219
fbapi20140410
fbapi20140116
fbapi20150313
fbapi20150629

需要注意的是,9.0.x上越狱手机存在一个漏洞,破坏了url方案。如果您正在运行越狱设备,请确保在Cydia中更新Patcyh。您可以通过调用
openURL:
openURL:options:completionHandler:
(iOS 10以后)直接打开应用程序,而无需进行条件检查
canOpenURL:
。 请阅读讨论部分,其中说明:

openURL:方法不受
LSApplicationQueriesSchemes
要求的约束


当我今天尝试从自己的应用程序调用Facebook时,我发现没有一个
LSApplicationQueriesSchemes
键可以添加到
Info.plist
(Xcode版本8.2.1(8C1002))。我用升华文本打开了
Info.plist
,并手动将其添加到文件中,然后它工作了。只是想让你知道,如果你找不到密钥,只需自己添加即可。

苹果在iOS 9上更改了canOpenURL方法。在iOS 9和iOS 10上检查URL方案的应用程序必须在提交给苹果时声明这些方案。

对于PayPal,请添加以下URL方案:


请参阅本文件,Swift 3.1、Swift 3.2、Swift 4

if let urlFromStr = URL(string: "instagram://app") {
    if UIApplication.shared.canOpenURL(urlFromStr) {
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(urlFromStr, options: [:], completionHandler: nil)
        } else {
            UIApplication.shared.openURL(urlFromStr)
        }
    }
}
在Info.plist中添加以下内容:

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

在Swift 4.2和Xcode 10.1中

在info.plist中,需要添加CbundleUrlSchemes和LSApplicationQueriesSchemes

-->在项目中选择info.plist

-->右键单击

-->选择“作为源代码打开”

请参见下面的屏幕截图

-->xml文件将被打开

-->复制-粘贴到代码下方,并用您的ID替换

gmail、fb、twitter和linked in的CbundleUrlSchemes和LSApplicationQueriesSchemes

<key>CFBundleURLTypes</key>
    <array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>li5****5</string>
            <string>com.googleusercontent.apps.8***************5f</string>
            <string>fb8***********3</string>
            <string>twitterkit-s***************w</string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>8*********3</string>
<key>FacebookDisplayName</key>
<string>K************ app</string>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-share-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>

    <string>twitter</string>
    <string>twitterauth</string>

    <string>linkedin</string>
    <string>linkedin-sdk2</string>
    <string>linkedin-sdk</string>

</array>
CbundleUrlTypes

什么是
+canOpenURL:<