0

This is driving me crazy. Every time I try to authenticate the local player with Game Center I get a thread-1 sigkill. It happens asynchronously after I set the localPlayer's authenticateHandler like so:

- (void)authenticateLocalPlayer
{
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
    {
        GKLocalPlayer __weak *localPlayer = [GKLocalPlayer localPlayer];
        localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
        {
            if (viewController != nil)
            {
                [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:viewController animated:YES completion:nil];
            }
            else if (localPlayer.isAuthenticated)
            {
                NSLog(@"Player authenticated");
            }
            else
            {
                NSLog(@"Player authentication failed");
            }
        };
    }
}

Any ideas?

3 Answers 3

0

I've often seen the systemVersion tested with a string comparison instead of a number comparison. Try just printing the value of

[[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0

to verify there's nothing wrong with that expression. I know the following method works:

-(BOOL) os6 {
    NSString *targetSystemVersion = @"6.0";
    NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
    if ([currentSystemVersion compare:targetSystemVersion options:NSNumericSearch] == NSOrderedAscending) {
        return NO;  //current system version is less than 6.0
    } else {
        return YES;
    }
}
2
  • That's not the issue - it correctly determines the OS and executes the contents of the if statement. It just crashes after launching the block asynchronously. Aug 9, 2013 at 5:08
  • [GKLocalPlayer localPlayer] returns a singleton and __weak causes a release to be sent to it at some time (I don't understand when that happens, but at some future time) and there's no need to release a singleton. localPlayer might be getting released, along with the block, before the block finishes executing. Try removing __weak;
    – RobertL
    Aug 10, 2013 at 1:35
0

[GKLocalPlayer localPlayer] returns a singleton and __weak releases it at some time (I don't understand when that happens, but at some future time). localPlayer might be getting released, along with the block, before the block finishes executing. There's no need to release a singleton. Try removing __weak.

0

Try putting __weak before GKLocalPlayer.

It's the only difference I can see between your code and the code I use...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.