繁体   English   中英

authenticateWithCompletionHandler:不推荐使用:首先在iOS 6.0中弃用

[英]authenticateWithCompletionHandler: is deprecated: first deprecated in iOS 6.0

我正在开发使用Game Center的游戏,然后我得到下一个警告;

...'authenticateWithCompletionHandler:'已弃用:首先在iOS 6.0中弃用

好的,我搜索并发现有新的代码用于验证本地用户,所以我更换了

旧代码:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

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

用新的:

- (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!");   
    }   
}

除了一件事,一切都很好。 如果用户未登录,则没有Game Center登录表单。 如果用户未登录,则使用旧代码显示Game Center登录表单。

有什么额外的代码我必须放入或其他什么?

额外信息: - 横向模式 - 部署目标:6.0

是的,您必须手动使用iOS6显示登录表单,这样您就可以更好地控制何时显示屏幕。 试一试

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM