[英]iOS9: canOpenURL returning false for WhatApp's url scheme
In my current project I need to share text on whatsapp from iOS app.在我当前的项目中,我需要从 iOS 应用程序在 whatsapp 上共享文本。
Here is my code to share text on whatsapp:这是我在whatsapp上共享文本的代码:
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
but canOpenURL always returning false in iOS9.但是canOpenURL在 iOS9 中总是返回 false。
Is there any iOS9 privacy policy?是否有任何 iOS9 隐私政策? Can anyone help me out?
谁能帮我吗?
In iOS 9 you must whitelist any URL schemes your App wants to query in Info.plist under the LSApplicationQueriesSchemes key (an array of strings):在 iOS 9 中,您必须将您的应用程序想要在 Info.plist 中的 LSApplicationQueriesSchemes 键(字符串数组)下查询的任何 URL 方案列入白名单:
For example:例如:
So in your case, instead of fb
and twitter
you will have to specify whatsapp
.因此,在您的情况下,您必须指定
whatsapp
而不是fb
和twitter
。
Note that this mechanism only applies to canOpenURL and not openURL.请注意,此机制仅适用于 canOpenURL 而不适用于 openURL。 You do not need to have a scheme listed in Info.plist to be able to open it with openURL.
您无需在 Info.plist 中列出方案即可使用 openURL 打开它。 Hope that helps.
希望有帮助。
In addition to @z22's answer if you need to add it textually (eg with Xamarin) then it looks like this:除了@z22 的答案之外,如果您需要以文本方式添加它(例如使用 Xamarin),那么它看起来像这样:
<dict>
...
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
</dict>
Step:1 Add LSApplicationQueriesSchemes in Info.plist步骤:1 在 Info.plist 中添加 LSApplicationQueriesSchemes
Step:2 Add whatsapp in items步骤:2 在项目中添加 whatsapp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.