开发者

Game Center localPlayer always authenticated

开发者 https://www.devze.com 2023-01-30 14:09 出处:网络
I\'m trying to detect whether the local player authentication is working or not and it appears that I always ge开发者_JAVA技巧t a positive result.

I'm trying to detect whether the local player authentication is working or not and it appears that I always ge开发者_JAVA技巧t a positive result.

Here is the code I am using:

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

I tested this code while disconnected from the network and here is the trace output:

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)

It clearly sees that the connection is offline but is still authenticating the player! Any ideas what's going on? I'm getting the same result on the device and in the simulator.

TIA


I think you shouldn't call authenticationChanged manually, take a look at Game Kit Programming Guide and follow the steps, that worked for me.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号