1
votes

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

2
i'm going to keep the question up in case there really is an error in my code, but i think game center's leaderboards are currently broken/undergoing an issue, because all the other games i have (not talking about mine, ones from the app store) display the exact same error "not ranked" and my score doesn't show on the leaderboard.Hades

2 Answers

3
votes
let player = GKLocalPlayer()

should be:

let player = GKLocalPlayer.localPlayer()

Examine the "Accessing the Shared Local Player" section in the GKLocalPlayer Class Reference documentation of the iOS Developer Library.

I tried to put this in a comment but I don't have enough points. Would someone with the necessary privileges please do so.

2
votes

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