SpriteKit中的游戏中心不解散排行榜 [英] Game Center In SpriteKit Not Dismissing Leader Board

查看:66
本文介绍了SpriteKit中的游戏中心不解散排行榜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

以下是我的代码示例:

- (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];

}

推荐答案

要回答我自己的问题... 我只是直接从Apple那里获取了代码

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];

}

这篇关于SpriteKit中的游戏中心不解散排行榜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆