I have an iOS Application which will load a particular view controller for authentication. However no matter what, the view controller will not load. Below is the code for my method which handles this (This is for a Game Center authentication popup):
-(void)authenticateLocalUser {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
if (viewController != nil) {
NSLog(@"AUTH VIEW CONTROLLER");
[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated) {
NSLog(@"User is authenticated");
}
else {
NSLog(@"Game Center Auth error.");
}
};
}
As you can see, I have followed the official Apple developer documentation. However the output of this method is always:
Game Center Auth Error (Last NSLog).
Why doesn't the view controller ever load? Because I need it to load so that the user can login to Game Center if they haven't done so already.
Thanks for your time, Dan.
It turned out that the issue in the end was to do with the Game Center app itself. I just logged in/out of that and it all worked. I have also now seen this same issue replicated in other iOS apps too which use Game Center.