iOS 9 无法使用 URL SCHEME 打开 Instagram 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30987986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 9 not opening Instagram app with URL SCHEME
提问by Sk.Azad
The following URL opens on iOS 8.3 and lower, but it does not work and iOS 9
以下 URL 在 iOS 8.3 及更低版本上打开,但在 iOS 9 上不起作用
let instagramURL = NSURL(string: "instagram://app")
Why won't the URL open?
为什么网址打不开?
回答by thelaws
iOS 9 has made a small change to the handling of URL scheme. You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes
key in your Info.plist
.
iOS 9 对 URL 方案的处理做了一个小改动。你必须列入白名单网址,你的应用程序将调出使用LSApplicationQueriesSchemes
在你的钥匙Info.plist
。
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. A “This app is not allowed to query for scheme xxx” syslog entry will appear.
If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently. A “This app is not allowed to query for scheme xxx” syslog entry will appear.
如果您对不在白名单中的 URL 调用“canOpenURL”方法,它将返回“NO”,即使安装了已注册处理此方案的应用程序。将出现“此应用程序不允许查询方案 xxx”系统日志条目。
如果您对不在白名单中的 URL 调用“openURL”方法,它将静默失败。将出现“此应用程序不允许查询方案 xxx”系统日志条目。
The author also speculates that this is a bug with the OS and Apple will fix this in a subsequent release.
作者还推测这是操作系统的错误,Apple 将在后续版本中修复此问题。
回答by Matthieu Rouif
As said above, you want to add a key in the info plist, here is the list for most social networks
如上所述,您想在信息 plist 中添加一个键,这是大多数社交网络的列表
<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. "Ha" is for snapchat
* 前 3 个匹配 Facebook (FBSDK 4.6):fbapi、fbauth2、fbshareextension。“哈”是用于 Snapchat
回答by Leo Natan
This is a new security feature of iOS 9. Watch WWDC 2015 Session 703for 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 构建的应用程序都需要LSApplicationQueriesSchemes
在其 plist 文件中提供一个条目,声明它尝试查询哪些方案。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme</string>
<string>urlscheme2</string>
<string>urlscheme3</string>
<string>urlscheme4</string>
</array>
回答by Awsed
Assuming two apps TestA and TestB. TestB wants to query if TestA is installed. "TestA" defines the following URL scheme in its info.plist file:
假设有两个应用程序 TestA 和 TestB。TestB 想查询是否安装了TestA。“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. This is done by adding the following code to TestB's info.plist file:
但这通常会在 iOS9 中返回 NO,因为需要将“TestA”添加到 TestB 的 info.plist 文件中的 LSApplicationQueriesSchemes 条目中。这是通过将以下代码添加到 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
回答by Kaey
From, Session 703 WWDC 2015:
来自 2015 年 WWDC 703 会议:
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. There is a new key,
LSApplicationQueriesSchemes
, and here you will need to add the list of schemes you want to are canOpenURL on.
当您为 iOS 9 构建应用程序并且想要调用 URL 方案时,您可以继续使用 URL 方案,您现在需要在您的应用程序 Info.plist 中声明它们。有一个新键,
LSApplicationQueriesSchemes
,在这里您需要添加您想要在 canOpenURL 上使用的方案列表。
回答by elbuild
Facebook sharing from a share dialog fails even with @Matthieu answer (which is 100% correct for the rest of social URLs). I had to add a set of URL i reversed from Facebook SDK.
即使使用@Matthieu 回答(对于其余社交 URL 100% 正确),从共享对话框中进行的 Facebook 共享也会失败。我必须添加一组从 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>
回答by iOS
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 AsSource 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.plistfile is
请参阅下面的屏幕,您的最终info.plist文件是
回答by Buzzrick
It is important to note that there was a bug with jailbroken phones on 9.0.x which broke url schemes. If you're running a jailbroken device then make sure you update Patcyh in Cydia
重要的是要注意 9.0.x 上的越狱手机存在一个错误,它破坏了 url 方案。如果您运行的是越狱设备,请确保在 Cydia 中更新 Patcyh
回答by iphondroid
Well you can open an app by calling openURL:
or openURL:options:completionHandler:
(iOS 10 onwards) directly without making the conditional check canOpenURL:
.
Please read the discussion sectionin Apple doc for canOpenURL: methodwhich says:
好吧,您可以通过调用openURL:
或openURL:options:completionHandler:
(iOS 10 以后)直接打开应用程序,而无需进行条件检查canOpenURL:
。请阅读Apple 文档中关于 canOpenURL: 方法的讨论部分,其中说:
the openURL: method is not constrained by the
LSApplicationQueriesSchemes
requirement.
openURL: 方法不受
LSApplicationQueriesSchemes
要求的约束。
回答by Dave
It doesn't seem anyone has addressed how to specify URLs with embedded parameters. Any URL that contains parameters it won't possible to specify the specific URL in LSApplicationsQueriesSchemes. For example, assume I have an email app that passes the the senders email address:
似乎没有人解决如何使用嵌入式参数指定 URL。任何包含参数的 URL 都无法在 LSApplicationsQueriesSchemes 中指定特定 URL。例如,假设我有一个传递发件人电子邮件地址的电子邮件应用程序:
myemail://[email protected]
The only way it seems to get it to work in iOS9 is to remove any parameters.
似乎让它在 iOS9 中工作的唯一方法是删除任何参数。