在iOS 7中展示Game Center排行榜的正确方法是什么?下面的代码在showViewController上崩溃,因为它仅支持iOS8。其他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)
}

最佳答案

如果您的应用定位到iOS 7.x,则应使用以下代码:

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


代替:

self.showViewController(gcViewController, sender: self)

关于ios - 由于不支持showViewController,因此显示排行榜崩溃的应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30609860/

10-11 14:48