Swift:检索LocalPlayer GC得分

时间:2016-06-21 13:06:26

标签: swift game-center-leaderboard

以下是获取本地玩家游戏中心得分的代码。

if (GKLocalPlayer.localPlayer().authenticated) {
    GKLeaderboard.loadLeaderboardsWithCompletionHandler { objects, error in
        if let e = error {
            print(e)
        } else {
            let leaderboards = objects! as [GKLeaderboard]
            print(leaderboards)
            for leaderboard in leaderboards {
                print(leaderboard)
                print(leaderboard.localPlayerScore) // This prints nil
            }
        }
    }
}

nil获得print(leaderboard.localPlayerScore),虽然我确信本地玩家已在此排行榜上保存了分数。我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

你必须打电话

leaderboard.loadScoresWithCompletionHandler() { scores, error in
    if error == nil {
          print(leaderboard.localPlayerScore)
    }
}