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