[英]iOS Facebook URL schemes doesn't open page in facebook app
I need to open facebook page in facebook app. 我需要在Facebook应用程序中打开Facebook页面。
This is my code 这是我的代码
let url : URL!
if (UIApplication.shared.canOpenURL(URL(string:"fb://")!)) {
//FIXME: Url is not working ✋
let pageName = "google"
// tried with fb://page?name=%@ not worked
let urlString = String.init(format: "fb://page?id=%@",pageName!)
url = URL.init(string: urlString)
} else {
url = URL.init(string: "https://www.facebook.com/google")
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url!, completionHandler: nil)
} else {
UIApplication.shared.openURL(url!)
}
it perfectly works in safari browser but not in facebook app. 它在Safari浏览器中完美运行,但在Facebook应用程序中则无效。
I have added the url schem in inof.plist
我已经在
inof.plist
添加了url schem
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
Can anyone help me to get out this problem? 谁能帮我解决这个问题?
Thanks In Advance!!!! 提前致谢!!!!
try this code , make sure use facebook id from page not page name 尝试此代码,请确保使用页面中的Facebook ID而不是页面名称
check this How to find page Id 检查此如何查找页面ID
let url : URL!
if (UIApplication.shared.canOpenURL(URL(string:"fb://")!)) {
//FIXME: Url is not working ✋
let pageName = "104958162837"
// tried with fb://page?name=%@ not worked
let urlString = String.init(format: "fb://profile/%@",pageName)
url = URL.init(string: urlString)
} else {
url = URL.init(string: "https://www.facebook.com/104958162837")
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url!, completionHandler: nil)
} else {
UIApplication.shared.openURL(url!)
}
And is it opening in a browser when you call UIApplication.shared.openURL(:)
? 当您调用
UIApplication.shared.openURL(:)
时,它是否会在浏览器中打开?
I didn't exactly understand your problem, but if I'm not mistaken, you've to put the Facebook App ID (it's the first thing that appears in your app in developers.facebook ) in your URL Types. 我没有完全理解您的问题,但是如果我没有记错的话,您必须将Facebook App ID (这是您的应用程序在developers.facebook中显示的第一件事)放入您的URL类型中。
This image should clarify what I'm trying to say: 该图像应阐明我要说的内容:
Do not forget the "fb"
String
before your App ID . 不要忘记您的App ID 之前的
"fb"
String
。
EDIT: Now that I've understood your problem, I can't be sure that you will be able to solve this - as you can see all this answers -, they apparently don't seem to work anymore , as the URL scheme changed a couple of times, and the one that you're using is actually the last "answered/used" on the referenced answer. 编辑:既然我已经了解了您的问题, 就不能确定您将能够解决此问题-正如您看到的所有答案 -随着URL方案的改变, 它们似乎不再起作用。几次,而您正在使用的实际上是引用答案上的最后一个“已回答/已使用”。 I can almost confirm that there is no supported way to do what you're trying because of this answer in fb-sdk github issues .
我几乎可以确认由于fb-sdk github问题中的答案,没有支持的方法来执行您正在尝试的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.