gpt4 book ai didi

ios - GKLocalPlayer 身份验证不起作用,但 isAuthenticated 返回 YES(Game Center 沙箱)

转载 作者:可可西里 更新时间:2023-11-01 06:15:09 26 4
gpt4 key购买 nike

我正致力于在我的游戏中集成回合制比赛,几天前我开始从 GameKit API 收到奇怪的错误,提示本地玩家未通过身份验证,尽管他已经通过身份验证。

当我启动应用程序时,authenticateHandler 被调用, View Controller 被显示,输入密码后,authenticaHandler 被再次调用,本地播放器似乎得到认证。 isAuthenticated 返回 YES

但是,一旦我开始使用任何 GameKit API,例如 loadFriendsWithCompletionHandler:,就会返回一个错误,指出玩家尚未通过身份验证。

这是处理身份验证更改的代码。

[[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController *viewController, NSError *error) {
if ([[GKLocalPlayer localPlayer] isAuthenticated]) {
// Player authenticated
} else {
// Player not authenticated

if (viewController != nil) {
// Present view controller
}
}
}];

这是我在调用任何 GameKit 方法时收到的错误消息。请注意,-isAuthenticated 返回错误时仍然返回 YES。

Error finding match: Error Domain=GKErrorDomain Code=6 "The requested operation could not be completed because local player has not been authenticated." UserInfo=0x14e9f950 {NSLocalizedDescription=The requested operation could not be completed because local player has not been authenticated.}
(lldb) print (BOOL) [[GKLocalPlayer localPlayer] isAuthenticated] (BOOL) $3 = YES

我正在 Game Center 沙箱中进行测试,几天前就开始了。以前,我根本没有遇到过这个问题。
当应用程序启动时,它只会发生大约三次中的一次。我已尝试删除该应用程序、重新启动我的设备、清理构建文件夹以及我能想到的所有其他方法。

我是不是遗漏了什么或者其他人是否遇到过类似的问题?

最佳答案

本富Apple documentation是一个值得一看的好地方。这是我建议的两件事 -

  1. 如果您的设备有不正确的日期。因此,请继续查看当前日期。

  2. 你可能已经做到了。我相信你 - iOS 模拟器 >> 重置内容和设置

您认为您使用 -[GKLocalPlayer loadFriendsWithCompletionHandler:] 的方式可能有问题吗?您上面的身份验证功能没有任何问题,但如果它适合您,我很乐意分享我的 -

-(void)authenticateLocalPlayer{

// Instantiate a GKLocalPlayer object to use for authenticating a player.
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {

// If it's needed display the login view controller.
[self presentViewController:viewController animated:YES completion:nil];

}
else {
if ([GKLocalPlayer localPlayer].authenticated) {
// If the player is already authenticated then indicate that the Game Center features can be used.

_gameCenterEnabled = YES;

}

else {
_gameCenterEnabled = NO;
}
}
};
}

关于ios - GKLocalPlayer 身份验证不起作用,但 isAuthenticated 返回 YES(Game Center 沙箱),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23541764/

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