And*_*ord 4 facebook url-scheme ios
我想从我的 iOS 应用程序中链接 Facebook 页面。如果 Facebook 应用程序安装在同一设备上,则该页面应显示在那里,否则在 Safari 中显示:
NSURL* facebookURL = [NSURL URLWithString:@"https://www.facebook.com/SomePage/"];
NSURL* facebookAppURL = [NSURL URLWithString:@"fb://profile/247377102029332"];
UIApplication* app = [UIApplication sharedApplication];
if ([app canOpenURL: facebookAppURL])
[app openURL:facebookAppURL];
else
[app openURL:facebookURL];
Run Code Online (Sandbox Code Playgroud)
理论上这应该有效:如果我直接在 Safari 中输入 facebookAppURL,或跳过检查canOpenURL,系统会询问我是否应在 Facebook 中打开该链接。单击“确定”后,Facebook 应用程序出现并显示该页面。
然而调用[app canOpenURL: facebookAppURL]会带来回报false。
同样的方法适用于 Twitter URL,例如:如果 Twitter 应用程序已安装并且可以处理 URL,则twitter://user?screen_name=...检查仅返回。true为什么 Facebook 链接失败?
你把这个添加到白名单了吗?从iOS9开始,出于安全原因,您需要将所有自定义URL方案列入白名单。您必须将应用程序将使用Info.plist中的LSApplicationQueriesSchemes键调用的 URL 列入白名单。
\n\n这是来自文档:
\n\n\n\n\n如果您对不在白名单中的 URL 调用 \xe2\x80\x9ccanOpenURL\xe2\x80\x9d 方法,它将返回 \xe2\x80\x9cNO\xe2\x80\x9d,即使安装了应用程序已注册处理此计划。将出现 \xe2\x80\x9cThis app is not allowed to query for schema xxx\xe2\x80\x9d syslog 条目。
\n\n如果您对不在白名单中的 URL 调用 \xe2\x80\x9copenURL\xe2\x80\x9d 方法,则该方法将会失败且无提示。将出现 \xe2\x80\x9cThis app is not allowed to query\n for schema xxx\xe2\x80\x9d syslog 条目。
\n
这就是创建白名单的方法
\n\n<key>LSApplicationQueriesSchemes</key>\n<array>\n <string>fb</string>\n <string>fbapi</string>\n <string>fbauth2</string>\n <string>fbshareextension</string>\n <string>fb-messenger-api</string>\n <string>twitter</string>\n <string>viber</string>\n <string>whatsapp</string>\n</array>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |