iosswiftxcodegame-centergame-center-leaderboard

Game Center Not Saving Scores


Game Center used to work perfectly a while ago for a different app that I made. However strange things are happening with my current one for about two weeks now.

Uploading and download report no error and I can see my score fine. But if I stop play my game and then 6 hours later come back to it, my score is no longer there in the game center. I mean, literally no score at all. Downloading from game center which works 6 hours ago now cannot retrieve my score.

Game center status is live. I can see my score and others in "manage score" section. However, I cannot see anything except my score in the leaderboard from GKGameCenterViewController.

As far as I'm concern, everything has been configured correctly. Game Center in app's capability is on.

Code for showing leaderboard:

func showLeaderBoard() {
    if GKLocalPlayer.localPlayer().isAuthenticated == false {
        self.present(authenticationViewController!, animated: true, completion: nil)
        return
    }

    let gamecenter = GKGameCenterViewController()
    gamecenter.gameCenterDelegate = self
    gamecenter.viewState = .leaderboards
    gamecenter.leaderboardIdentifier = leaderBoardID

    present(gamecenter, animated: true, completion: nil)
}

Code for downloading score:

func downloadBestScoreFromGameCenter() {
    if GKLocalPlayer.localPlayer().isAuthenticated == false {return}
    print("Downloading Score...")

    let leaderBoard = GKLeaderboard()
    leaderBoard.identifier = leaderBoardID
    leaderBoard.loadScores(completionHandler: {
        [unowned self] (scores, error) in

        print("Download Error: \(error)")

        scores?.forEach({print("\($0.player?.displayName!) \($0.value)")})

        if let localPlayerScore = leaderBoard.localPlayerScore?.value {
            self.bestScore = Int(localPlayerScore)
            self.saveGameForCurrentState()
        } else {
            self.bestScore = 0
        }
    })
}

And uploading

func uploadBestScoreToGameCenter() {
    if GKLocalPlayer.localPlayer().isAuthenticated == false {return}

    let scoreItem = GKScore(leaderboardIdentifier: leaderBoardID)
    scoreItem.value = Int64(self.bestScore)

    GKScore.report([scoreItem], withCompletionHandler: {
        (error) in
        if let error = error {
            print(error)
        } else {
            print("Upload complete: \(scoreItem.value)")
        }
    })
}

Solution

  • Ok the leaderboard is now working today. I guess you just have to wait people.