authenticateWithCompletionHandler:不推荐使用:首先在iOS 6.0中弃用 [英] authenticateWithCompletionHandler: is deprecated: first deprecated in iOS 6.0
问题描述
我正在开发使用Game Center的游戏,我接下来会收到警告;
I am working on game which is using Game Center and I get next warning;
...'authenticateWithCompletionHandler:'已弃用:首先弃用iOS 6.0
好的,我搜索并发现有新的验证本地用户代码所以我更换了
Ok, I searched and found out that there is new code for authenticate Local User so I replaced
旧代码:
- (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登录表单。
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?
额外信息:
- 横向模式
- 部署目标:6.0
Extra info: - landscape mode - deployment target: 6.0
推荐答案
是的,您必须手动使用iOS6显示登录表单,这样您就可以更好地控制何时显示屏幕。尝试一下
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
}
};
这篇关于authenticateWithCompletionHandler:不推荐使用:首先在iOS 6.0中弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!