Reputation: 83
Dears i got an error "Value of type 'GameScene' has no member 'present' "
I want to add a label to share the best-score in facebook the code below works fine in normal 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)
}
}
}
Upvotes: 1
Views: 53
Reputation: 10105
To be able to present such alert you might use the rootViewController
, doing so:
UIApplication.shared.keyWindow?.rootViewController?.present(facebookSheet, animated: true, completion: nil)
Upvotes: 1