I have a question, help me understand the topic. Honestly, I've spent several days studying the topic, but it's not working yet.
There is a simple game on SpriteKit, Swift 3.
I'm trying to implement Leaderboard Game Center.
iTunes Connect has already set up, the leaderboard has already created, the test user has already created.
When I start the game, the user logs in as they should. The button to display the board created and I can open my leaderboard in the Game Center.
The problem is that the value of the points scored in the leaderboard is not updated.
My game scores are stored in variable "score" In gamescene.swift, I have two functions for saving and overriding:
func saveHighscore(gameScore: Int) {
if GKLocalPlayer.localPlayer().isAuthenticated {
print("\n Success! Sending highscore of \(score) to leaderboard")
let scoreReporter = GKScore(leaderboardIdentifier: “MY_ID_THERE”)
scoreReporter.value = Int64(gameScore)
let scoreArray: [GKScore] = [scoreReporter]
GKScore.report(scoreArray, withCompletionHandler: {error -> Void in
if error != nil {
print("An error has occured: \(String(describing: error))")
}
})
}
}
func overrideHighestScore(gameScore: Int) {
UserDefaults.standard.integer(forKey: "highestScore")
if gameScore > UserDefaults.standard.integer(forKey: "highestScore") {
UserDefaults.standard.set(gameScore, forKey: "highestScore")
UserDefaults.standard.synchronize()
saveHighscore(gameScore: score)
print(score.hashValue)
}
}
I call both functions when I press the button
saveHighscore (gameScore: score)
overrideHighestScore (gameScore: score)
The console displays output correctly, for example, when collecting five points the output will be a message called:
Success! Sending the highscore of 5 to the leaderboard
but the value of the variable score in the game center is not sent and there are zero values achieved at the first access to the board
I really hope for your help.
Sincerely, Eugene.