在iOS 7中展示Game Center排行榜的正确方法是什么?下面的代码在showViewController
崩溃,因为它只支持iOS 8.其他Stack Overflow帖子建议在iOS 7中使用presentViewController
,但这只显示一个空白的排行榜。
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)
}
答案 0 :(得分:1)
如果您的应用定位到iOS 7.x,则应使用以下代码:
self.presentViewController(gcViewController, animated: true, completion: nil)
而不是:
self.showViewController(gcViewController, sender: self)