【问题标题】:Share Best Score on Facebook在 Facebook 上分享最佳成绩
【发布时间】:2018-03-02 13:48:57
【问题描述】:

亲爱的,我收到一个错误“'GameScene' 类型的值没有成员'present'”

我想添加一个标签以在 facebook 中分享最佳分数,下面的代码在普通 ViewController 中可以正常工作

for touch in touches {
    let touchLocation = touch.location(in: self)
    if atPoint(touchLocation).name == "shareButtoon" {
        if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook) {
            let facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
            facebookSheet.setInitialText(bestScore.text)
            self.present(facebookSheet, animated: true, completion: nil)
        } else {
            let alert = UIAlertController(title: "Accounts", message: "Please login to your Facebook account", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }
}

【问题讨论】:

标签: ios swift facebook


【解决方案1】:

为了能够显示此类警报,您可以使用rootViewController,这样做:

UIApplication.shared.keyWindow?.rootViewController?.present(facebookSheet, animated: true, completion: nil)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-18
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    相关资源
    最近更新 更多