我正在尝试将游戏中心功能添加到我的应用程序中,并且此功能旨在获得用户的高分并进入排行榜。问题在于它仅上传第一个高分。当用户获得新的高分但它确实起作用时,我会再次调用它。

//send high score to leaderboard
    func saveHighscore(score:Int)
    {
        //check if user is signed in
        if GKLocalPlayer.localPlayer().authenticated
        {
            let scoreReporter = GKScore(leaderboardIdentifier: "774433bbcc11bbvv") //leaderboard id here
            scoreReporter.value = Int64(circleView1.score) //score variable here (same as above)
            let scoreArray: [GKScore] = [scoreReporter]
            GKScore.reportScores(scoreArray,withCompletionHandler: {(error : NSError?) -> Void in
                if error != nil
                {
                    print("error")
                }
            })
        }
    }

最佳答案

您是否可以尝试从此使用完成处理程序替换该块:

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


对此:

GKScore.reportScores(scoreArray) {(error) in
    self.lastError = error
}

关于ios - Swift Game Center保存高分功能不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36000197/

10-11 23:16
查看更多