我正在开发使用 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!");
}
}
除了一件事之外,一切都很好。如果用户未登录,则没有游戏中心登录表单。使用旧代码,如果用户未登录,它会显示游戏中心登录表单。
是否有任何我必须输入的额外代码或其他内容?
额外信息:
- 横向模式
- 部署目标: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
}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)