Had to re-create the method in the same class. Cannot present a view controller from a external class/
Not presenting Authentication view controller game kit ios 7
-
28-06-2022 - |
Pergunta
I am on ios 7 and with this code:
-(IBAction)authenticateLocalPlayerWithViewController
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
localPlayer.authenticateHandler = ^(UIViewController *receivedViewController, NSError *error){
if (receivedViewController != nil)
{
[self presentViewController:receivedViewController animated:YES completion:nil];
} else if (blockLocalPlayer.isAuthenticated) {
signinButton.hidden = YES;
leaderboardButton.alpha = 1.0;
leaderboardButton.enabled = YES;
achievementsButton.alpha = 1.0;
achievementsButton.enabled = YES;
NSString *identifier;
[self reportAchievement1Identifier:identifier percentComplete:((interactiveHighscore/10000)*100.0)];
[self reportAchievement2Identifier:identifier percentComplete:((interactiveHighscore/100000)*100.0)];
[self reportAchievement3Identifier:identifier percentComplete:((interactiveHighscore/1000000)*100.0)];
[self reportAchievement4Identifier:identifier percentComplete:((interactiveHighscore/100000000)*100.0)];
[self reportAchievement5Identifier:identifier percentComplete:((allCoins/100000)*100.0)];
[self submitMyInteractiveScore];
[self submitMyNormalScore];
BOOL isRunMoreThanOnceGC = [[NSUserDefaults standardUserDefaults] boolForKey:@"isRunMoreThanOnceGC"];
if (!isRunMoreThanOnceGC) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Game Center Sign In Gift"
message:@"Thanks for signing in with game center here is 50 Coins."
delegate:nil
cancelButtonTitle:@"Thanks!."
otherButtonTitles:nil];
[alert show];
allCoins = [[NSUserDefaults standardUserDefaults] integerForKey:@"allCoins"];
allCoins += 50;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isRunMoreThanOnceGC"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
} else {
signinButton.hidden = NO;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Game Center Not Available"
message:@"Uh Oh! Seems there was an error trying to sign in for Game Center. Try logging in through the Game Center app."
delegate:nil
cancelButtonTitle:@"Ok, Thanks."
otherButtonTitles:nil];
[alert show];
}
NSLog(@"Error: %d", [error code]);
};
}
am trying to authenticate the user. First on the root controller's viewDidLoad I call it with this:
//get game center
LeaderboardsViewController *LVC = [[LeaderboardsViewController alloc] init];
[LVC authenticateLocalPlayerWithViewController];
Then I get this:
Error: 0 Warning: Attempt to present on whose view is not in the window hierarchy!
So I try to press the button in the gamecenterviewcontroller class (thats where the authenticate method is) and I get nothing. Nothing in the log and nothing appears....
Running ios 7 GM Build.
Thanks a lot!
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow