GKLocalPlayer身份验证不起作用,但是isAuthenticated返回YES(“游戏中心"沙箱) [英] GKLocalPlayer authentication not working, but isAuthenticated returns YES (Game Center sandbox)

查看:154
本文介绍了GKLocalPlayer身份验证不起作用,但是isAuthenticated返回YES(“游戏中心"沙箱)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将基于回合的比赛整合到我的游戏中,几天前,我开始从GameKit API中收到奇怪的错误消息,指出本地玩家即使经过身份验证也未通过身份验证.

I'm working on integrating turn based matches in my game and a few days ago I started getting weird errors from the GameKit API saying that the local player is not authenticated, even though he is.

启动应用程序时,将调用authenticateHandler,显示视图控制器,并在输入密码后再次调用authenticaHandler,并且本地播放器似乎已通过身份验证. isAuthenticated返回YES.

When I launch the app, the authenticateHandler is called, the view controller is displayed and after entering the password, the authenticaHandler is called again and the local player seems to be authenticated. isAuthenticated returns YES.

但是,一旦我开始使用任何像loadFriendsWithCompletionHandler:这样的GameKit API,就会返回一个错误,提示玩家尚未通过身份验证.

But as soon as I start using any of the GameKit APIs like loadFriendsWithCompletionHandler:, an error is returned saying that the player has not been authenticated.

这是用于处理身份验证更改的代码.

This is the code for handling authentication changes.

[[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.

And this is the error message I receive when calling any of the GameKit methods. Please note that -isAuthenticated still returns YES when the error is returned.

找到错误的匹配项:错误域= GKErrorDomain代码= 6由于未验证本地播放器,因此无法完成请求的操作. UserInfo = 0x14e9f950 {NSLocalizedDescription =由于未验证本地播放器,所以无法完成请求的操作.}
(lldb)打印(BOOL)[[GKLocalPlayer localPlayer]已通过身份验证] (布尔)$ 3 =是

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沙箱中进行测试,它是几天前开始发生的.以前,我根本没有遇到这个问题.
启动该应用程序时,它只会发生大约3次.我尝试删除该应用程序,重新启动设备,清理构建文件夹以及其他我能想到的东西.

I'm testing in the Game Center sandbox and it started happening a few days ago. Previously, I didn't experience the problem at all.
It only happens about one of three times when the app is started. I have tried deleting the app, restarting my devices, cleaning the build folder and everything else I could think of.

我错过了什么吗?或者其他人遇到过类似的问题吗?

Am I missing something or has anybody else experienced similar problems?

推荐答案

丰富的

This rich Apple documentation is a great place to look at. Here are 2 things which I would suggest -

    如果您的设备具有
  1. Game Center无法完成身份验证 日期不正确.因此,请继续检查当前日期.

  1. Game Center fails to complete authentication if your device has incorrect dates. So, go ahead and check the current date.

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

You might have done this. I trust you - iOS Simulator >> Reset Content and Settings

您是否认为使用-[GKLocalPlayer loadFriendsWithCompletionHandler:]的方式可能有问题?上面的身份验证功能没什么问题,但我很乐意分享我的身份验证功能-

Do you think there could be something wrong with the way you are using -[GKLocalPlayer loadFriendsWithCompletionHandler:]? Nothing wrong with your authentication function above, but I'd love to share mine if it works for you -

-(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;
            }
        }
    };
}

这篇关于GKLocalPlayer身份验证不起作用,但是isAuthenticated返回YES(“游戏中心"沙箱)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆