Game Center In SpriteKit Not Dismissing Leader Board

百般思念 提交于 2019-12-11 04:09:29

问题


After a lot of searching on here I finally found a way for Game Center to display in SpriteKit but now I can't get the leaderboardViewControllerDidFinish method to call. I use this code in a different app and it works fine but for some reason with the code being modified for SpriteKit its just not working. Thank you in advance!

Here is a sample of my code:

- (void)showGameCenterButtonPressed:(id)sender {
{
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"You must enable Game Center!"
                                                          message:@"Sign in through the Game Center app to enable all features"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
        [message show];
    } else {
        GKGameCenterViewController *leaderboardViewController = [[GKGameCenterViewController alloc] init];
        if (leaderboardViewController != NULL)
        {

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

} }

- (void)leaderboardViewControllerDidFinish:(GKGameCenterViewController *)viewController {
NSLog(@"in leaderboardControllerDidFinish");
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];

}

回答1:


To answer my own question... I just took the code straight from Apple

- (void)showGameCenterButtonPressed:(id)sender {
{
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"You must enable Game Center!"
                                                          message:@"Sign in through the Game Center app to enable all features"
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
        [message show];
    } else {
        GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
        if (gameCenterController != nil)
        {
            gameCenterController.gameCenterDelegate = self;
            gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
            UIViewController *vc = self.view.window.rootViewController;
            [vc presentViewController: gameCenterController animated: YES completion:nil];
        }
    }
}

}

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController {

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

}



来源:https://stackoverflow.com/questions/20308044/game-center-in-spritekit-not-dismissing-leader-board

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!