斯威夫特 3.0 / iOS10:
let fbUrl: NSURL = NSURL(string: "fb://profile/55555555555555")!
let fbWebUrl: NSURL = NSURL(string: "https://facebook.com/yourFacebookPageName")!
if (UIApplication.shared.canOpenURL(fbUrl as URL)) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(fbUrl as URL, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(fbUrl as URL)
}
} else {
if #available(iOS 10.0, *) {
UIApplication.shared.open(fbWebUrl as URL, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(fbWebUrl as URL)
}
}
“55555555555555”应替换为您可以从http://findmyfbid.com获得的数字 Facebook ID ,“yourFacebookPageName”应替换为页面的用户名。
不要忘记在应用程序的 Info.plist(在 LSApplicationQueriesSchemes 下)中启用 fb url 方案。