在 iOS 7 中显示 Game Center 排行榜的正确方法是什么?下面的代码崩溃了,showViewController
因为它只支持 iOS 8。其他 Stack Overflow 帖子建议使用presentViewController
iOS 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)
}