使用 RoboVM 和 libgdx 向 GameCenter 提交分数

Submitting score to GameCenter using RoboVM and libgdx

我正在使用 libgdx 和 robovm。

当我尝试在 iOS 上将分数提交到 GameCenter 的排行榜时出现错误。我能够显示排行榜。这是我得到的错误:

*** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKScore must specify a leaderboard.' libc++abi.dylib: terminating with uncaught exception of type NSException

与此类似SO-post,但它是objective-c所以我不明白答案。

这是我用于显示排行榜的代码(有效)

public void getLeaderboardGPGS() {

    // If player is not authenticated, do nothing
    if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) {
        return;
    } 
    GKGameCenterViewController gameCenterView = new GKGameCenterViewController();

    gameCenterView.setGameCenterDelegate(new GKGameCenterControllerDelegateAdapter() {
        @Override
        public void didFinish (GKGameCenterViewController gameCenterViewController) {
            dismissViewControllerAndNotifyListener(gameCenterViewController, GKGameCenterViewControllerState.Leaderboards);
        }
    });
    gameCenterView.setViewState(GKGameCenterViewControllerState.Leaderboards);

    gameCenterView.setLeaderboardIdentifier(identifier);


    keyWindow.getRootViewController().presentViewController(gameCenterView, true, null);
}

这是我提交乐谱的代码(这行不通)

public void submitScoreGPGS(int score, MyLeaderBoardCallback callback) {

    // If player is not authenticated, do nothing
    if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) {
        //listener.scoreReportFailed(buildUnauthenticatedPlayerError());
        Gdx.app.log("Gamecenter","Notlogedin");
        return;
    }
    GKScore scoreReporter = new GKScore(identifier);

    scoreReporter.setValue(score);
    scoreReporter.setLeaderboardIdentifier(identifier);
    //scoreReporter.setShouldSetDefaultLeaderboard(true);
    //scoreReporter.setContext(0);

    NSArray<GKScore> scores = new NSArray<GKScore>(scoreReporter);

    Gdx.app.log("Gamecenter","Report socre");
    GKScore.reportScores(scores, new VoidBlock1<NSError>() {
        @Override
        public void invoke (NSError error) {
            if (error != null) {
                Gdx.app.log("Gamecenter","scorereportfailed");
            } else {
                Gdx.app.log("Gamecenter","scorereportcompleted");
            }
        }
    });

}

有人知道问题出在哪里吗?我试过用谷歌搜索,但关于 "robovm and gamekit/gamecenter".

的信息很少

包含排行榜 ID 的变量由于某种原因被垃圾回收。必须在 scoreReporter.setLeaderboardIdentifier("my hard coded id"); 处对字符串进行硬编码。奇怪....