I know, there are some threads about this, but I didn't really get what I excatly have to do for my class.
- (void)authenticateLocalUser {
if (!gameCenterAvailable) return;
NSLog(@"Authenticating local user...");
if ([GKLocalPlayer localPlayer].authenticated == NO) {
[[GKLocalPlayer localPlayer]
authenticateWithCompletionHandler:nil];
} else {
NSLog(@"Already authenticated!");
}
}
How can I fix the problem, it says "authenticateWithCompletionHandler" is deprecated.
Can somebody help me out?
EDIT:
With the new code
- (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!");
}
}
The error is : Capturing "localPlayer" strongly in this block is likely to lead to a retain circle . Its in the if(localPlayer.isAuthenticated).
also, the Game Center is not popping up anymore. If i want to let it pop up again with this code:
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
}
};
Same Error here.
Here as img: