Search code examples
iosios9xcode7game-centergame-center-leaderboard

game center leaderboard not working ("no scores")


right now I'm done with the making of my game and all i need to add are the in app purchases and the leaderboards, and as to not mess up anything I'm doing this with a test app. my leaderboard is now showing and even though I'm logged into game center when testing (on both a real device and simulator) i get "no scores" when viewing the leaderboard. but my code is fine, i've been going through the apple documentations and other tutorials for days. but all tutorials are outdated and the apple documentations are very unclear on some specific things. but i think my code is fine:

let HighscoreDefault = NSUserDefaults.standardUserDefaults()
    if (HighscoreDefault.valueForKey("highScore") != nil){

        highScore = HighscoreDefault.valueForKey("highScore") as! NSInteger
    }
    else {

        highScore = 0
    }

    if (score > highScore){

        let HighscoreDefault = NSUserDefaults.standardUserDefaults()
        HighscoreDefault.setValue(score, forKey: "highScore")
        highScore = HighscoreDefault.valueForKey("highScore") as! NSInteger
        saveScore(score)
    }

thats my score saving method in game, and this is how i'm uploading it to the leaderboard:

    func saveScore(score: Int){
    let player = GKLocalPlayer()
    if player.authenticated == true {

        let scoreReporter = GKScore(leaderboardIdentifier: "testingleaderboard101") //leaderboard id here

        scoreReporter.value = Int64(highScore) //score variable here (same as above)

        let scoreArray: [GKScore] = [scoreReporter]

        GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError?) -> Void in
            if error != nil {
                print("error")
            } else {
                print("reported correctly")
            }
        })

    }
}

i'm pretty certain the error isn't here, but i'm posting just in case it is.

here is what i'm getting in the logger:

plugin com.apple.GameCenterUI.GameCenterDashboardExtension invalidated


Solution

  • i fixed it, some bug in ios 9 is causing GKLocalPlayer().authenticated to return false even if the player is logged in. so in the savescore function, don't check if the player is authenticated