With some research, this is what I thought to be the right code. Everything seems to be working and there are NO errors. The first high score uploaded shows on the leaderboard (for both Game Center accounts I am using for testing), but any score uploaded after the initial high score (which should replace it) isn't shown (I have tried using more than one account, same issue). Here is my code (I call for this function when a Button is pressed). Everything loads up fine and the Game Center window closes perfectly with NO errors, but the score for account 1 remains at 0 (which was the first score loaded) while the score for account 2 remains at 2 (which was the first score loaded). (highScore is a saved NSInteger before this function is called) Please help!
func saveHighscore() {
//check if user is signed in
if GKLocalPlayer.localPlayer().authenticated {
let gameScoreReporter = GKScore(leaderboardIdentifier: "color_runner_leaderboard")
gameScoreReporter.value = Int64(highScore)
let scoreArray1: [GKScore] = [gameScoreReporter]
GKScore.reportScores(scoreArray1, withCompletionHandler: {(NSError) -> Void in
if NSError != nil {
print(NSError!.localizedDescription)
} else {
print("completed Easy")
}
})
}
}
This code shows the leaderboard:
//show leaderboard screen
func showLeader() {
let vc = self.view?.window?.rootViewController
let gc = GKGameCenterViewController()
gc.gameCenterDelegate = self
vc?.presentViewController(gc, animated: true, completion: nil)
}
This code is what uploads the score (which doesn't seem to be working after the FIRST score is loaded) and displays the leaderboard
let highScoreDefault = NSUserDefaults.standardUserDefaults()
if highScoreDefault.valueForKey("HighScoreSaved") != nil {
highScore = highScoreDefault.valueForKey("HighScoreSaved") as! NSInteger!
[saveHighscore()]
}
[showLeader()]