我正在尝试在swift精灵套件游戏中设置游戏中心。以下是在我的应用程序代理中完成的
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.authenticateHandler也总是返回一个nil viewController。请让我知道我做错了什么以及如何解决这个问题。
我也遇到了同样的问题。
尝试从设备中删除应用程序,然后转到游戏中心下的设备设置并启用沙箱。
然后在设备上再次运行游戏,它应该会显示游戏中心登录窗口。
我尝试在模拟器中运行我的应用程序,验证窗口显示良好。我不知道为什么它不能在我的设备上工作。
我也遇到了同样的情况。在多个设备上尝试过,但结果相同。删除应用程序/更改游戏中心设置没有帮助。不过,您的代码看起来不错。看起来Swift的GC完全崩溃了。。