Search code examples
ioscocoa-touchgame-centerviewcontrollerpresentviewcontroller

Game center authentication view not showing - iOS


I have a simple iOS app which makes use of Game Center. However recently when updating it to iOS 7, I noticed that the authenticate method does not work.

One of the issues is with the code I am using to present the view controller to the user if they need to sign in to game centre, it no longer pops up the game centre login window in the app.

Another issue I have is that I can't find what method to use instead of the deprecated "authenticateWithCompletionHandler".

Here is my code:

-(void)authenticateLocalUser {

GKLocalPlayer.localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {

    if (GKLocalPlayer.localPlayer.authenticated) {
        // Already authenticated
    }

    else if (viewController) {
        [self presentViewController:viewController animated:YES completion:nil];
    }

    else {
        // Problem with authentication, probably bc the user doesn't use Game Center.
    } 
};

if ([GKLocalPlayer localPlayer].authenticated == NO) {

    [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)  {
        [self callDelegateOnMainThread: @selector(processGameCenterAuth:) withArg:NULL error: error];
    }];
}
}

Thanks for your time, Dan.


Solution

  • No matter I managed to figure it out in the end. As for 'authenticateWithCompletionHandler', I used this:

    [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:viewController animated:YES completion:nil];