Link 从 IOS 应用到 Facebook

Link to Facebook from IOS app

我正在尝试从我的应用程序创建一个 link 到我们的业务 Facebook 页面。到目前为止,它似乎没有用。我的目标是点击一个按钮 'Facebook',弹出一个警告,询问这个人是否想打开带有 yes/cancel 答案的 Facebook,然后在应用程序中或网络。我已经尝试搜索,但我发现的所有内容似乎都无法帮助我完全满足我的需要 我尝试将我自己的按钮与 link 合并到我想要的页面,但我似乎没有得到任何地方。当我 运行 我的应用程序在模拟器中时,该按钮的功能就在于它按下和突出显示但不提供警报,然后应该允许该人转到 Facebook 页面。

谁能帮我实现这个。到目前为止,这就是我所拥有的:

@IBAction func displayFacebookPage(_ sender: Any) {
    let alert = UIAlertController(title: "Open in Facebok?", message: nil, preferredStyle: UIAlertControllerStyle.alert)

    alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.default) {_ in

        let appURL = URL(string: "fb:/
        let webURL = URL(string: "https:/
        let application = UIApplication.shared

        if application.canOpenURL(appURL) {
            if #available(iOS 10.0, *) {
                application.open(appURL)
            } else {
                if #available(iOS 10.0, *) {
                    application.open(webURL as URL)
                } else {
                }
            }

            alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.cancel, handler: nil))
            self.present(alert, animated: true, completion: nil)

        }
    }
} 

谢谢!

你的牙套不正确。使用以下代码

 let alert = UIAlertController(title: "Open in Facebok?", message: nil, preferredStyle: UIAlertControllerStyle.alert)
        let action = UIAlertAction(title: "Yes", style: UIAlertActionStyle.default) { _ in
            let appURL = URL(string: "fb:/")
            let webURL = URL(string: "https:/")
            let application = UIApplication.shared

            if application.canOpenURL(appURL!) {
                if #available(iOS 10.0, *) {
                    application.open(appURL!)
                } else {
                    if #available(iOS 10.0, *) {
                        application.open(webURL!)
                    } else {
                    }
                }
            }
        }
        let noAction = UIAlertAction(title: "No", style: UIAlertActionStyle.cancel, handler: nil)
        alert.addAction(action)
        alert.addAction(noAction)
        self.present(alert, animated: true, completion: nil)