在 Google 和 Stackoverflow 上多次搜索后,我找不到问题的解决方案。
目前,我的应用程序通过 Safari 打开 Facebook 页面。但我希望在 Facebook 应用程序中自动打开同一页面。您能给我一个解决方案吗?
这是我实现的代码,但 Facebook 应用程序无法打开...
@IBAction func facebookButton(_ sender: Any) {
if let appURL = URL(string: "facebook://") {
let canOpen = UIApplication.shared.canOpenURL(appURL)
print("\(canOpen)")
let appName = "Facebook"
let appScheme = "\(appName)://"
let appSchemeURL = URL(string: appScheme)
if
UIApplication.shared.canOpenURL(appSchemeURL! as URL) {
UIApplication.shared.open(appSchemeURL!, options: [:], completionHandler: nil)
} else {
let alert = UIAlertController(title: "\(appName) Erreur !", message: "L'application \(appName) ne peut pas s'ouvrir. Merci de l'installer depuis l'App Store.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
最佳答案
您是否已将 facebook 方案添加到 info.plist 中的 LSApplicationQueriesSchemes 中?
<key>LSApplicationQueriesSchemes</key>
<array>
<string>facebook sceheme here</string>
</array>
关于ios - 使用 Swift 使用 Facebook 链接页面打开 Facebook 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55753244/