So I have a Game that uses Game Center, I used a tutorial online. It authenticates the user when the View did load. To see your leaderboards and achievements, you press a button, and that code is separate from the authentication. It was all working fine, until I launch the app in airplane mode. For some reason, since it can't connect to the Game Center Server, it gives up and crashes.
Authentication code (ViewController.m, viewDidLoad)
if ([GKLocalPlayer localPlayer].authenticated == NO) {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
})];
} else {
NSLog(@"Already authenticated!");
}
Also, I don't think this is causing the problem, because it crashes on launch, and I don't know if this code gets run on launch. (I copied most of this code from a tutorial) but here it is:
(GCHelper.m)
#pragma mark Authentication
- (void)authenticationChanged {
if ([GKLocalPlayer localPlayer].isAuthenticated && !userAuthenticated) {
NSLog(@"Authentication changed: player authenticated.");
userAuthenticated = TRUE;
[self loadLeaderBoardInfo];
// [self loadAchievements];
} else if (![GKLocalPlayer localPlayer].isAuthenticated && userAuthenticated) {
NSLog(@"Authentication changed: player not authenticated.");
userAuthenticated = FALSE;
}
}
- (void)authenticateLocalUserOnViewController:(UIViewController*)viewController
setCallbackObject:(id)obj
withPauseSelector:(SEL)selector
{
if (!gameCenterAvailable) return;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
NSLog(@"Authenticating local user...");
if (localPlayer.authenticated == NO) {
[localPlayer setAuthenticateHandler:^(UIViewController* authViewController, NSError *error) {
if (authViewController != nil) {
if (obj) {
[obj performSelector:selector withObject:nil afterDelay:0];
}
[viewController presentViewController:authViewController animated:YES completion:^ {
}];
} else if (error != nil) {
// process error
}
}];
}
else {
NSLog(@"Already authenticated!");
}
}
My question is, Why does it crash on launch in airplane mode? This is the error message:
2014-10-28 16:18:05.895 Rock Paper Scissors Challenge[10372:704073] -[GKLocalPlayerInternal name]: unrecognized selector sent to instance 0x7ced9750
2014-10-28 16:18:05.992 Rock Paper Scissors Challenge[10372:704073] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GKLocalPlayerInternal name]: unrecognized selector sent to instance 0x7ced9750' * First throw call stack:
100% of the time it crashes in airplane mode, 100% of the time it works, and it says "welcome back" when I'm not in airplane mode I don't get it
Please help, Thanks!