以下是获取本地玩家游戏中心得分的代码。
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)
,虽然我确信本地玩家已在此排行榜上保存了分数。我错过了什么吗?
答案 0 :(得分:3)
你必须打电话
leaderboard.loadScoresWithCompletionHandler() { scores, error in
if error == nil {
print(leaderboard.localPlayerScore)
}
}