ios - 游戏中心排行榜不工作 ("no scores")

标签 ios ios9 xcode7 game-center game-center-leaderboard

现在我已经完成了我的游戏制作,我需要添加的是应用内购买和排行榜,并且为了不搞砸我正在使用测试应用做的任何事情。我的排行榜现在正在显示,即使我在测试时(在真实设备和模拟器上)登录到游戏中心,查看排行榜时我也会得到“无分数”。但我的代码很好,我已经浏览了苹果文档和其他教程好几天了。但是所有的教程都已经过时了,苹果的文档在一些具体的事情上也很不清楚。但我认为我的代码很好:

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)
    }

这就是我在游戏中的得分保存方法,这就是我将其上传到排行榜的方式:
    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")
            }
        })

    }
}

我很确定错误不在这里,但我发布以防万一。

这是我在记录器中得到的:

插件 com.apple.GameCenterUI.GameCenterDashboardExtension 无效

最佳答案

let player = GKLocalPlayer()

应该:
let player = GKLocalPlayer.localPlayer()

检查 iOS 开发人员库的 GKLocalPlayer 类引用文档中的“访问共享本地播放器”部分。

我试图把它放在评论中,但我没有足够的分数。请有必要特权的人这样做。

关于ios - 游戏中心排行榜不工作 ("no scores"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33200192/

相关文章:

iOS9 ActivityManager.startActivityUpdatesToQueue 错误

ios - 无法在 XCode 7 beta 2 中调试

iphone - UITableViewCell accessoryType 已设置,但 accessoryView 为 nil。如何设置 accessoryView backgroundColor?

ios - 我可以禁用 UITextField 中的表情符号图标吗?

ios - 以编程方式添加标签,与 Storyboard 中的标签对齐

ios - 升级 iPhone/Xcode 破坏了我的 cocoapod 库

iphone - Apple 设备的型号名称

iOS 状态栏忽略根 Controller 中的 supportedInterfaceOrientations

iphone - 检测 iOS 模拟器与 iOS 设备

ios - 检查互联网连接是否可用