SpriteKit游戏中心不解散领导委员会

时间:2013-12-01 02:23:41

标签: ios game-center sprite-kit

经过大量的搜索,我终于找到了一种方法让Game Center在SpriteKit中显示,但现在我无法调用leaderboardViewControllerDidFinish方法。我在不同的应用程序中使用此代码,它工作正常但由于某些原因,为SpriteKit修改代码它只是不工作。提前谢谢!

以下是我的代码示例:

- (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 个答案:

答案 0 :(得分:2)

回答我自己的问题...... 我只是直接从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];

}