【发布时间】:2019-09-09 05:12:32
【问题描述】:
在 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)
}
}
}
【问题讨论】: