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


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.


我修正了它,在ios 9中的一些错误导致GKLocalPlayer()。即使玩家登录也会返回false。所以在savedcore函数中,不要检查玩家是否被认证

链接地址: http://www.djcxy.com/p/68236.html

上一篇: 使用游戏中心在应用内对游戏进行评分

下一篇: 游戏中心排行榜不工作(“没有分数”)