在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>