亲爱的我得到一个错误“类型的价值'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)
}
}
}
答案 0 :(得分:1)
为了能够提供此类提醒,您可以使用rootViewController
,这样做:
UIApplication.shared.keyWindow?.rootViewController?.present(facebookSheet, animated: true, completion: nil)