authenticateWithCompletionHandler: is deprecated: first deprecated in iOS 6.0

让人想犯罪 __ 提交于 2019-11-30 04:02:22

问题


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


回答1:


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
} 
};


来源:https://stackoverflow.com/questions/14423995/authenticatewithcompletionhandler-is-deprecated-first-deprecated-in-ios-6-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!