1

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)
        }
    }
}
mugx
  • 9,869
  • 3
  • 43
  • 55
Malsaeed 55
  • 85
  • 1
  • 1
  • 7
  • 1
    Possible duplicate of [Swift & SpriteKit - How to present alert view in GameScene](https://stackoverflow.com/questions/39557344/swift-spritekit-how-to-present-alert-view-in-gamescene) – Malik Mar 02 '18 at 05:45

1 Answers1

1

To be able to present such alert you might use the rootViewController, doing so:

UIApplication.shared.keyWindow?.rootViewController?.present(facebookSheet, animated: true, completion: nil)
mugx
  • 9,869
  • 3
  • 43
  • 55