Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

authenticateWithCompletionHandler: is deprecated: first deprecated in iOS 6.0

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

like image 316
iWizard Avatar asked Jan 20 '13 11:01

iWizard


1 Answers

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
} 
};
like image 74
Kaan Dedeoglu Avatar answered Sep 25 '22 10:09

Kaan Dedeoglu