authenticateWithCompletionHandler: is deprecated: first deprecated in iOS 6.0

iWizard picture iWizard · Jan 20, 2013 · Viewed 7.8k times · Source

I am working on game which is using Game Center and I get next warning;

... 'authenticateWithCompletionHandler:' is deprecated: first deprecated in iOS 6.0

Ok, I searched and found out that there is new code for authenticate Local User so I replaced

old code:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
    } else {
        NSLog(@"Already authenticated!");
    }
}

with the new one:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");

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

        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
        //[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE!
            if(localPlayer.isAuthenticated) {
                //do some stuff
            }else {
                // not logged in   
            }
        })]; 
    } else {
        NSLog(@"Already authenticated!");   
    }   
}

and everything is ok except one thing. If user is not logged in there is no Game Center login form. With old code it shows up Game Center login form if user is not logged in.

is there any extra code that I must put in or something else?

Extra info: - landscape mode - deployment target: 6.0

Answer

Kaan Dedeoglu picture Kaan Dedeoglu · Jan 21, 2013

Yes, you have to manually present the login form with iOS6, this gives you more control over when to present the screen. Give this a try

localPlayer.authenticateHandler = ^(UIViewController *viewController,NSError *error) {
if (localPlayer.authenticated) { 
//already authenticated
} else if(viewController) {
[self presentViewController:viewController];//present the login form
} else {
//problem with authentication,probably bc the user doesn't use Game Center
} 
};