ios游戏中心身份验证不断失败

用户名

基本上,根据ViewControllerviewdidload方法,我将:

[self authenticateLocalUser];

authenticateLocalUser方法是:

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

if (localPlayer.isAuthenticated == NO)
{
    NSLog(@"FAILED");
}

为什么不进行身份验证?类方法不应该GKLocalPlayer自动进行身份验证吗?另外,如果它可以进行身份​​验证,我是否应该在顶部显示“ welcome back _ _”?我根本没有得到这个横幅。我需要事先做些事情吗?

上师

在iOS6及更高版本中,您需要提供带有setAuthenticateHandler api的Game Center登录视图。

这是代码:

#define CHECK_IOS_LESS_THAN(version) ([[[UIDevice currentDevice] systemVersion] \
compare:version options:NSNumericSearch] == NSOrderedAscending)

- (void) authenticateLocalUser
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

    if (CHECK_IOS_LESS_THAN(@"6.0"))
    {
        // ios 5.x and below
        [localPlayer authenticateWithCompletionHandler:^(NSError *error)
         {
             [self checkLocalPlayer];
         }];
    }
    else
    {        
        // ios 6.0 and above
        [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error)
                                             {
                                                 if (!error && viewcontroller)
                                                 {
                                                     [self.navController
                                                      presentViewController:viewcontroller animated:YES completion:nil];
                                                 }
                                                 else
                                                 {
                                                     [self checkLocalPlayer];
                                                 }
                                             })];
    }
}



- (void)checkLocalPlayer
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

    if (localPlayer.isAuthenticated)
    {
        /* Perform additional tasks for the authenticated player here */

        [self  processGameCenterLoginSuccess];
    }
    else
    {
        /* Perform additional tasks for the non-authenticated player here */
        [self processGameCenterLoginFaild];
    }
}

添加此代码后,转到设备设置并重置:设备:设置->常规->重置->重置所有设置模拟器:设置->常规->重置->重置位置和隐私

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章