Game Center Authentication Handler View Controller is always zero
I am trying to set up Game Center in a quick game with a sprite pack. The App Delegate does the following:
func authenticateLocalPlayer(){
let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in
//handle authentication
if (viewController != nil){
self.window?.rootViewController?.presentViewController(viewController, animated: true, completion: nil)
}
else{
if (localPlayer.authenticated){
gameCenterEnabled = true
//Get the default leaderboard identifier.
localPlayer.loadDefaultLeaderboardIdentifierWithCompletionHandler({ (leaderboardIdentifierr: String!, error: NSError!) -> Void in
if (error != nil){
NSLog("%@", [error.localizedDescription])
}
else{
leaderboardIdentifier = leaderboardIdentifierr
}
})
}
else{
gameCenterEnabled = false
}
}
}
}
The problem I am facing is that localPlayer.autheniticateHandler always returns nil viewController even though my local player is not authenticated. Please let me know what I am doing wrong and how to fix it.
+3
source to share
3 answers