如何实施 GameCenter 排行榜?

how do I implement GameCenter Leaderboard?

我无法遵循 Stack Overflow 上的其他教程和答案,那么如何在 Swift 中的 SpriteKit 中在我的游戏中实现 GameCenter 排行榜?将使用的代码是什么,它会放在 GameScene 还是 GameViewController 中?我已经在 iTunes Connect 上设置了排行榜。我该怎么做?谢谢!

首先你必须验证玩家:

 var localPlayer = GKLocalPlayer.localPlayer()
    localPlayer.authenticateHandler = {(viewController : UIViewController!, error : NSError!) -> Void in
        if ((viewController) != nil) {
            self.presentViewController(viewController, animated: true, completion: nil)
        }else{

            println((GKLocalPlayer.localPlayer().authenticated))
        }
    }

然后就可以打开排行榜了:

 func showLeaderboard() {


        var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
        gcViewController.gameCenterDelegate = self

        gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards


        gcViewController.leaderboardIdentifier = "YOUR_BOARD_NAME"

        self.showViewController(gcViewController, sender: self)
        self.navigationController?.pushViewController(gcViewController, animated: true)

    }
    func gameCenterViewControllerDidFinish(gcViewController: GKGameCenterViewController!)
    {

        self.dismissViewControllerAnimated(true, completion: nil)
    }

我建议在您的视图控制器中执行这些操作。在 viewDidAppear 上验证播放器而不是 viewDidLoad