Malsaeed 55
Malsaeed 55

Reputation: 83

Share Best Score on Facebook

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

Answers (1)

mugx
mugx

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

Related Questions