我试图检测本地播放器身份验证是否正常工作,看起来我总是得到一个积极的结果。游戏中心localPlayer始终认证
这里是我使用的代码:我测试这个代码,同时断开网络连接,并在这里
//--------------------------------------------------------------
- (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
我有类似的问题。我正在测试我的游戏中心功能,并希望看到在飞行模式下会发生什么。如果我在进入飞行模式之前登录了Game Center,该应用程序将不会授权玩家(当然),但是在执行[localPlayer isAuthenticated]时,我会得到一个带登录到Game Center的玩家ID的YES。你有没有找到解决你的问题? – Structurer 2011-08-30 10:32:34