[英]iOS 9 not opening Instagram app with URL SCHEME
The following URL opens on iOS 8.3 and lower, but it does not work and iOS 9 以下网址在iOS 8.3和更低版本上打开,但在iOS 9和更高版本上不起作用
let instagramURL = NSURL(string: "instagram://app")
Why won't the URL open? 为什么URL无法打开?
iOS 9 has made a small change to the handling of URL scheme. iOS 9对URL方案的处理进行了小的更改。 You must whitelist the url's that your app will call out to using the
LSApplicationQueriesSchemes
key in your Info.plist
. 您必须使用
Info.plist
的LSApplicationQueriesSchemes
密钥将应用将调出的URL列入白名单。
Please see post here: http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes 请在此处查看帖子: http : //awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes
The main conclusion is that: 主要结论是:
If you call the “canOpenURL” method on a URL that is not in your whitelist, it will return “NO”, even if there is an app installed that has registered to handle this scheme.
如果您对不在白名单中的URL调用“ canOpenURL”方法,则即使安装了已注册用于处理此方案的应用程序,该方法也会返回“ NO”。 A “This app is not allowed to query for scheme xxx” syslog entry will appear.
将会出现“此应用程序不允许查询方案xxx”的系统日志条目。
If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently.
如果您对不在白名单中的URL调用“ openURL”方法,则该方法将自动失败。 A “This app is not allowed to query for scheme xxx” syslog entry will appear.
将会出现“此应用程序不允许查询方案xxx”的系统日志条目。
The author also speculates that this is a bug with the OS and Apple will fix this in a subsequent release. 作者还推测这是操作系统的错误,Apple将在后续版本中修复此错误。
As said above, you want to add a key in the info plist, here is the list for most social networks 如上所述,您想在信息列表中添加密钥,这是大多数社交网络的列表
<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>
* The first 3 match Facebook (FBSDK 4.6): fbapi, fbauth2, fbshareextension. *前三场比赛的Facebook(FBSDK 4.6):fbapi,fbauth2,fbshareextension。 "Ha" is for snapchat
“ Ha”是指手套
This is a new security feature of iOS 9. Watch WWDC 2015 Session 703 for more information. 这是iOS 9的新安全功能。有关更多信息,请观看WWDC 2015 Session 703 。
Any app built with SDK 9 needs to provide a LSApplicationQueriesSchemes
entry in its plist file, declaring which schemes it attempts to query. 使用SDK 9构建的任何应用都需要在其plist文件中提供
LSApplicationQueriesSchemes
条目,以声明其尝试查询的方案。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme</string>
<string>urlscheme2</string>
<string>urlscheme3</string>
<string>urlscheme4</string>
</array>
Assuming two apps TestA and TestB. 假设有两个应用程序TestA和TestB。 TestB wants to query if TestA is installed.
TestB要查询是否已安装TestA。 "TestA" defines the following URL scheme in its info.plist file:
“ TestA”在其info.plist文件中定义以下URL方案:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>testA</string>
</array>
</dict>
</array>
The second app "TestB" tries to find out if "TestA" is installed by calling: 第二个应用程序“ TestB”尝试通过调用以下命令来确定是否安装了“ TestA”:
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"TestA://"]];
But this will normally return NO in iOS9 because "TestA" needs to be added to the LSApplicationQueriesSchemes entry in TestB's info.plist file. 但这通常会在iOS9中返回NO,因为“ TestA”需要添加到TestB的info.plist文件中的LSApplicationQueriesSchemes条目中。 This is done by adding the following code to TestB's info.plist file:
这是通过将以下代码添加到TestB的info.plist文件中来完成的:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>TestA</string>
</array>
A working implementation can be found here: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example 一个有效的实现可以在这里找到: https : //github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example
From, Session 703 WWDC 2015: 从2015年的703会议WWDC:
You can continue to use URL schemes when you build your app for iOS 9 and you want to call URL schemes, you will now need to declare them in your apps Info.plist.
在为iOS 9构建应用程序时,您可以继续使用URL方案,并且要调用URL方案,现在需要在应用程序Info.plist中声明它们。 There is a new key,
LSApplicationQueriesSchemes
, and here you will need to add the list of schemes you want to are canOpenURL on.有一个新的密钥
LSApplicationQueriesSchemes
,在这里您将需要添加canOpenURL所在的方案列表。
Facebook sharing from a share dialog fails even with @Matthieu answer (which is 100% correct for the rest of social URLs). 即使使用@Matthieu答案,从共享对话框进行的Facebook共享也会失败(对于其余的社交URL,这是100%正确的)。 I had to add a set of URL i reversed from Facebook SDK.
我必须添加从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>
It is important to note that there was a bug with jailbroken phones on 9.0.x which broke url schemes. 重要的是要注意,9.0.x上的越狱电话存在一个错误,该错误破坏了URL方案。 If you're running a jailbroken device then make sure you update Patcyh in Cydia
如果您正在运行越狱设备,请确保在Cydia中更新Patcyh
Well you can open an app by calling openURL:
or openURL:options:completionHandler:
(iOS 10 onwards) directly without making the conditional check canOpenURL:
. 那么,您可以直接调用
openURL:
或openURL:options:completionHandler:
iOS 10开始)来打开应用,而无需进行条件检查canOpenURL:
Please read the discussion section in Apple doc for canOpenURL: method which says: 请阅读Apple文档中有关canOpenURL:方法的讨论部分 :
the openURL: method is not constrained by the
LSApplicationQueriesSchemes
requirement.openURL:方法不受
LSApplicationQueriesSchemes
要求的约束。
In Swift 4.2 and Xcode 10.1 在Swift 4.2和Xcode 10.1中
In info.plist need to add CFBundleURLSchemes and LSApplicationQueriesSchemes. 在info.plist中需要添加CFBundleURLSchemes和LSApplicationQueriesSchemes。
--> Select info.plist in your project, ->在您的项目中选择info.plist,
--> right click, ->右键单击,
--> Select Open As Source Code ->选择打开为 源代码
See the below screen shot 请参阅下面的屏幕截图
--> xml file will be opened -> xml文件将打开
--> copy - paste below code and replace with your ID's ->复制-粘贴以下代码,并替换为您的ID
CFBundleURLSchemes and LSApplicationQueriesSchemes for gmail, fb, twitter and linked in. gmail,fb,twitter和已链接的CFBundleURLSchemes和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>
See below screen your final info.plist file is 看到下面的屏幕,您的最终info.plist文件是
It doesn't seem anyone has addressed how to specify URLs with embedded parameters. 似乎没有人解决过如何使用嵌入式参数指定URL。 Any URL that contains parameters it won't possible to specify the specific URL in LSApplicationsQueriesSchemes.
任何包含参数的URL都无法在LSApplicationsQueriesSchemes中指定特定的URL。 For example, assume I have an email app that passes the the senders email address:
例如,假设我有一个通过发件人电子邮件地址的电子邮件应用程序:
myemail://mailto?bob@gmail.com
The only way it seems to get it to work in iOS9 is to remove any parameters. 使其在iOS9中正常工作的唯一方法是删除所有参数。
Apple更改了iOS 9上的canOpenURL方法。正在iOS 9和iOS 10上检查URL方案的应用程序必须在提交给Apple时声明这些方案。
Swift 3.1, Swift 3.2, Swift 4 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)
}
}
}
Add these in Info.plist : 将它们添加到Info.plist中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
When I tried to call Facebook from my own app today, I found that there is no a LSApplicationQueriesSchemes
key I can add to the Info.plist
(Xcode Version 8.2.1 (8C1002)). 今天,当我尝试从自己的应用程序调用Facebook时,发现没有可添加到
Info.plist
(Xcode版本8.2.1(8C1002))的LSApplicationQueriesSchemes
密钥。 I opened the Info.plist
with Sublime Text and manually added it into the file, then it worked. 我用Sublime Text打开了
Info.plist
并将其手动添加到文件中,然后它开始工作。 Just to let you know that if you cannot find the key, simply add it yourself. 只是让您知道,如果找不到密钥,只需自己添加即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.