我正在尝试在Swift Sprite Kit游戏中设置Game Center。以下是我的应用程序委托中完成的内容:
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
}
}
}
}
我遇到的问题是,localPlayer.autheniticateHandler总是返回一个空的viewController,即使我的本地玩家没有经过身份验证。请告诉我我做错了什么以及如何解决这个问题。