gpt4 book ai didi

swift2 - GameCenter 无法工作,身份验证和排行榜未显示

转载 作者:行者123 更新时间:2023-12-02 02:46:55 24 4
gpt4 key购买 nike

对于 Swift 2,GameCenter 不适合我。身份验证 ViewController 未显示...这是我的函数 authenticateLocalPlayer():

func authenticateLocalPlayer() {
var localPlayer = GKLocalPlayer()
localPlayer.authenticateHandler = {(viewController: UIViewController?, error: NSError?) -> Void in
if (viewController != nil) {
self.presentViewController(viewController!, animated: true, completion: nil)
print("Not Authenticated. ")
} else {
print("Authenticated. ")
}
}
}

它每次都返回“未验证”,但不显示 ViewController。有什么解决办法吗?

最佳答案

此解决方案在 Xcode 7.0 中使用 Swift 2 正确呈现 viewController。

请注意,我在 if 语句开始之前更改了代码。我相信语法可能在最近的软件更新中发生了变化,因为我也遇到了这个问题。

在我的应用程序中,我在 GameViewController 类的 viewDidLoad() 方法中调用了authenticateLocalPlayer()。

func authenticateLocalPlayer() {

let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController, error) -> Void in

if (viewController != nil) {
self.presentViewController(viewController!, animated: true, completion: nil)
}

else {
print((GKLocalPlayer.localPlayer().authenticated))
}
}
}

关于swift2 - GameCenter 无法工作,身份验证和排行榜未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31911509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com