在Facebook上分享最佳分数

问题描述 投票:1回答:1

亲爱的,我得到一个错误“类型的价值'GameScene'没有成员'现在'”

我想添加一个标签来分享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个回答
1
投票

为了能够提供这样的警报,您可以使用rootViewController,这样做:

UIApplication.shared.keyWindow?.rootViewController?.present(facebookSheet, animated: true, completion: nil)
© www.soinside.com 2019 - 2024. All rights reserved.