Game Center Leaderboard not dismissing

Posted by FireStorm on Game Development See other posts from Game Development or by FireStorm
Published on 2014-08-22T22:19:18Z Indexed on 2014/08/22 22:35 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

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!

© Game Development or respective owner

Related posts about ios

Related posts about game-center