我正在尝试检测本地玩家身份验证是否正常工作,而且似乎我总是得到肯定的结果。
这是我正在使用的代码:
//--------------------------------------------------------------
- (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