游戏中心localPlayer始终通过身份验证

时间:2010-12-13 18:25:07

标签: iphone objective-c cocoa-touch ios game-center

我正在尝试检测本地播放器身份验证是否正常工作,看起来我总是得到肯定的结果。

以下是我正在使用的代码:

//--------------------------------------------------------------
- (void)authenticateLocalPlayer 
{
    NSLog(@"Authenticating local player %@ (%d)", ([GKLocalPlayer localPlayer].authenticated? @"YES":@"NO"), [GKLocalPlayer localPlayer].authenticated);
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
            [self callDelegateOnMainThread:@selector(authenticationChanged:) 
                                   withArg:nil 
                                     error:error];
        }];
    }
}

//--------------------------------------------------------------
- (void)authenticationChanged:(NSError *)error {
    if (error != nil) {
        NSLog(@"Error authenticating local player: %@", [error localizedDescription]);
    }
    NSLog(@"Authentication changed %@ (%d)", ([GKLocalPlayer localPlayer].authenticated? @"YES":@"NO"), [GKLocalPlayer localPlayer].authenticated);
}

我在断开网络时测试了这段代码,这里是跟踪输出:

2010-12-13 13:20:59.799 LittleScreams[954:307] Authenticating local player NO (0)
2010-12-13 13:21:01.616 LittleScreams[954:307] Error authenticating local player: The Internet connection appears to be offline.
2010-12-13 13:21:01.621 LittleScreams[954:307] Authentication changed YES (1)

它清楚地看到连接处于脱机状态但仍在验证播放器!有什么想法发生了什么?我在设备上和模拟器中得到了相同的结果。

TIA

1 个答案:

答案 0 :(得分:0)

我认为您不应该手动调用authenticationChanged,请查看Game Kit编程指南并按照适用于我的步骤进行操作。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html