0

在 iOS 7 中显示 Game Center 排行榜的正确方法是什么?下面的代码崩溃了,showViewController因为它只支持 iOS 8。其他 Stack Overflow 帖子建议使用presentViewControlleriOS 7,但只显示空白排行榜。

func showLeaderboards() {
    // User logged into GameCenter?
    if (!GKLocalPlayer.localPlayer().authenticated) {
        println("Local player not authenticated")
        // Show message
        return
    }

    // If here, user authenticated. Present leaderboards.
    var gcViewController = GKGameCenterViewController()
    gcViewController.gameCenterDelegate = self
    gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
    gcViewController.leaderboardIdentifier = HighScoresLeaderboardKey
    self.showViewController(gcViewController, sender: self)
    self.navigationController?.pushViewController(gcViewController, animated: true)
}
4

1 回答 1

1

如果您的应用面向 iOS 7.x,则应使用以下代码:

self.presentViewController(gcViewController, animated: true, completion: nil)

代替:

self.showViewController(gcViewController, sender: self)
于 2015-06-03T02:52:58.170 回答