Vincent DUPONT
Vincent DUPONT

Reputation: 27

Swift - FirstViewController and GKGameCenterControllerDelegate

I want to include a GameCenter Leaderboard in my app but I have one problem.

When I want to show LeaderBoard, I use this code :

//shows leaderboard screen
func showLeader() {
    var vc = self.view?.window?.rootViewController
    var gc = GKGameCenterViewController()
    gc.gameCenterDelegate = self
    vc?.presentViewController(gc, animated: true, completion: nil)
}

For that, I must had GKGameCenterControllerDelegate in my class like that :

class FirstViewController: UIViewController, GKGameCenterControllerDelegate {

When I do that, I have an error : 'type FirstViewController' does not to conform to protocol 'GKGameCenterControllerDelegate'.

Any solution ?

Upvotes: 0

Views: 111

Answers (1)

Kendel
Kendel

Reputation: 1708

You need to include the following method:

 func gameCenterViewControllerDidFinish(gcViewController: GKGameCenterViewController!)
    {
        // By tapping on Done, the Game Center window will be dismissed.
        self.dismissViewControllerAnimated(true, completion: nil)
    }

More info here: https://developer.apple.com/library/mac/documentation/GameKit/Reference/GKGameCenterViewControllerDelegate_Ref/

Upvotes: 1

Related Questions