iWi*_*ard 7 iphone ios game-center
我正在开发使用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!");
}
}
Run Code Online (Sandbox Code Playgroud)
用新的:
- (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!");
}
}
Run Code Online (Sandbox Code Playgroud)
除了一件事,一切都很好.如果用户未登录,则没有Game Center登录表单.如果用户未登录,则使用旧代码显示Game Center登录表单.
有什么额外的代码我必须放入或其他什么?
额外信息: - 横向模式 - 部署目标:6.0
Kaa*_*glu 10
是的,您必须手动使用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
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7723 次 |
| 最近记录: |