1
\$\begingroup\$

I was implementing Game Center into my app and all was going well except for the leaderboard done button not dismissing the leaderboard even with gameCenterControllerDidFinish added in. I call up the leaderboard with the touch of a button in the .m file as so:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 UITouch *touch = [touches anyObject];
 CGPoint location = [touch locationInNode:self];
 SKNode *node = [self nodeAtPoint:location];



 if ([node.name isEqualToString:@"rankButton"]) {

    [self runAction:[SKAction playSoundFileNamed:@"fishtran.m4a" waitForCompletion: NO]];
     GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] 
  init];
        if (gameCenterController != nil)
   {

        gameCenterController.viewState = GKGameCenterViewControllerStateAchievements;
        UIViewController *vc = self.view.window.rootViewController;
        [vc presentViewController: gameCenterController animated: YES completion:nil];
    }
} else if ([node.name isEqualToString:@"Leaderboard"]) {
    GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc]  
  init];
    if (gameCenterController != nil)
    {

        gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
        UIViewController *vc = self.view.window.rootViewController;
        [vc presentViewController: gameCenterController animated: YES completion:nil];
    }
}

... and then I added thegameCenterControllerDidFinish immediately after as so:

- (void)gameCenterControllerDidFinish:(GKGameCenterViewController*)gameCenterController {

    UIViewController *vc = self.view.window.rootViewController;
    [vc dismissViewControllerAnimated:YES completion:nil];
}  

and the done button still doesn't work and i haven't been able to find any solutions. And yes, I do have GKGameCenterControllerDelegate in my .h file. Any help would be greatly appreciated, Thanks!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

just use gameCenterController for dismissing.

[gameCenterController dismissViewControllerAnimated:YES completion:nil];
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .