0

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!

user3386154
  • 99
  • 1
  • 10
  • 1
    The error is in some code you didn't post. You should always post all your relevant code. – Claus Jørgensen Oct 28 '14 at 23:18
  • That is pretty much all the authentication code, I searched the project for GKLocalPlayerInternal and I got no results – user3386154 Oct 30 '14 at 13:03
  • This could be a SpriteKit bug by apple. see another post [here][1] [1]: http://stackoverflow.com/questions/26334489/strange-exception-with-gamecenter – Bill Nov 09 '14 at 02:09
  • That's what I think. When I ran the debugger, it pointed to a file I couldn't edit. I had to take out Game Center until further updates come out. – user3386154 Nov 09 '14 at 23:26

0 Answers0