gpt4 book ai didi

iphone - authenticateWithCompletionHandler : is deprecated: first deprecated in iOS 6. 0

转载 作者:可可西里 更新时间:2023-11-01 03:29:10 26 4
gpt4 key购买 nike

我正在开发使用 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
}
};

关于iphone - authenticateWithCompletionHandler : is deprecated: first deprecated in iOS 6. 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14423995/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com