gpt4 book ai didi

ios - 方法已弃用 authenticateWithCompletionHandler

转载 作者:行者123 更新时间:2023-11-29 01:37:43 25 4
gpt4 key购买 nike

我知道,有一些关于这方面的线索,但我并没有真正明白我必须为我的类(class)做些什么。

- (void)authenticateLocalUser {

if (!gameCenterAvailable) return;

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

我该如何解决这个问题,它说“authenticateWithCompletionHandler”已被弃用。

有人可以帮帮我吗?

编辑:

使用新代码

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

错误是:在此 block 中强烈捕获“localPlayer”很可能会导致保留循环。它在 if(localPlayer.isAuthenticated) 中。

此外,游戏中心不再弹出。如果我想让它用这段代码再次弹出:

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

同样的错误。

这里是 img:

enter image description here

最佳答案

你用这个方法替换了这个方法:

-(void)authenticateLocalUser {


NSLog(@"Authenticating local user ...");
if(!gameCenterAvailable) {
return;
}

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
NSLog(@"authenticateHandler");
if (viewController != nil)
{
NSLog(@"viewController != nil");
}
else if (localPlayer.isAuthenticated)
{
NSLog(@"localPlayer already authenticated");
//do some stuff
}
else
{
NSLog(@"local player not authenticated");
// not logged in
}
};
}

关于ios - 方法已弃用 authenticateWithCompletionHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32781850/

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