iOS Game Center Leaderboard forces a default score of 0

120 Views Asked by At

I'm currently working on a racing game where the player's goal is to complete a task in the shortest time possible.

I need to save the users fastest time, but the Game Center always has a default time of 0 seconds. And since Game Center only saves 1 value per user, it tosses the player's actual time/score.

The only thing I was able to do was to temporarily set the leaderboard to save the longest time. That way a time longer than 0 secs would be saved. Then I would switch it back so that shorter times would get saved.

This is obviously not a solution for a production level game.

Is there any wrong with the way I'm saving or retrieving scores? I'm at a loss for how I can either turn off that default 0 sec time or override it.

    func loadLeaderBoard(level level:Int){
    let leaderboardRequest = GKLeaderboard() as GKLeaderboard!
    leaderboardRequest.identifier = "level\(level)ID"
    if leaderboardRequest != nil {
        leaderboardRequest.loadScoresWithCompletionHandler({ (score, error) -> Void in
            if error != nil {
                print(error)
            } else {
                if let myscore:[GKScore] = score {
                    self.records.updateValue(myscore.first!.formattedValue!, forKey: level)
                }
            }
        })
    }
}


func recordTime(level level: Int, record:Int64){
    let score = GKScore(leaderboardIdentifier: "level1ID")
    score.value = record
    GKScore.reportScores([score]) { (error) -> Void in
        if error != nil {
            print(error)
        }else {
            print("Score reported: \(score.value)")
        }
    }
}

enter image description here

0

There are 0 best solutions below