So far I have had success in implementing Game Center for my app. Authorizing players is OK, so is reporting Achievements.
My issue is when I wanted to test app behavior with my iPad in flight mode.
The player will not get authorized (as I expected, so no issue) with this code.
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if ([localPlayer isAuthenticated] == YES){
NSLog(@"The local player has already authenticated.");
return;
} else {
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil){
NSLog(@"Successfully authenticated the local player.");
NSLog(@"Player Alias = %@", [localPlayer alias]);
} else {
NSLog(@"Failed to authenticate the player with error = %@", error);
}
}];
}
But when I later on in a UIView check if the player is authorized (so I know if I shall enable my show achievement button) with this code [achievementButton setEnabled:[localPlayer isAuthenticated]];
I always get a YES as long as a user was logged in to Game Center before entering Flight Mode.
It seems like even if there is no connection to Game Center servers a previous authorized player is still seen as authorized.
This leads to that my button开发者_StackOverflow is shown but of course Game Center reports that it can not connect.
So, what would be the best way to check that a true connection to Game Center is available?
Cheers
I don't think there is an API to check that, but you can always make a call to one of the API that is going to return results, like getting leaderboards. It will fail if you're not connected.
Have a look at the SCNetworkReachability
interfaces. Search in the docs for SCNetworkReachability, and there are other SO questions that reference this. Basically, you can use the Reachability APIs to continuously keep updated a flag that you can check to know whether or not you have a network connection.
精彩评论