3
votes

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.

1
Hey there eugene, i had gone through the same situation as yours earlier this year. I contacted apple support and it seems it was an error on their behalf. Similar to you, leaderboards wouldn't update after several days. I would suggest that you contact Apple iTunes Connect. They should be able to fix it.sicvayne

1 Answers

0
votes

I hope you have properly configured leaderboard at https://itunesconnect.apple.com

Please refer below screen


enter image description here


Also refer below code to save score on leaderboard.

func saveScoreOnGameCenter()
{
    let leaderboardID = 111
    let sScore = GKScore(leaderboardIdentifier: leaderboardID)
    sScore.value = Int64(10)

    GKScore.reportScores([sScore], withCompletionHandler: { (error: NSError?) -> Void in
        if error != nil {
            print(error!.localizedDescription)
        } else {
            print("Score submitted")

        }
    })
}

Hope this helps you to figure out problem.