访问游戏中心高分ios phonegap插件

访问游戏中心高分ios phonegap插件,ios,cordova,game-center,leaderboard,Ios,Cordova,Game Center,Leaderboard,所以 我正在使用phonegap和lee的ios插件访问gamecenter。一切都很顺利,但我想拿到前十名的分数 我应该能够将这个[Apple示例代码][1]集成到这个插件中 我添加了-void getScores:CDVInvokedUrlCommand*命令;去游戏中心 然后在gamecenter.m文件中,我现在正在进行操作 - (void) getScores:(CDVInvokedUrlCommand*)command; { NSMutableDiction

所以

我正在使用phonegap和lee的ios插件访问gamecenter。一切都很顺利,但我想拿到前十名的分数

我应该能够将这个[Apple示例代码][1]集成到这个插件中

我添加了-void getScores:CDVInvokedUrlCommand*命令;去游戏中心

然后在gamecenter.m文件中,我现在正在进行操作

- (void) getScores:(CDVInvokedUrlCommand*)command;

    {
        NSMutableDictionary *args = [command.arguments objectAtIndex:0];
        NSString *leaderboardId = [args objectForKey:@"leaderboardId"];

        __block CDVPluginResult* pluginResult = nil;
        NSMutableArray *topScores = [NSMutableArray array];
        GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
        if (leaderboardRequest != nil)
        {
            leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
            leaderboardRequest.timeScope = GKLeaderboardTimeScopeToday;
            leaderboardRequest.identifier = leaderboardId;
            leaderboardRequest.range = NSMakeRange(1,10);
            [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
                if (error != nil)
                {
                    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
                }
                if (scores != nil)
                {

                    for (GKScore* score in scores)
                    {

                        NSMutableDictionary *entry = [NSMutableDictionary dictionary];
                        entry[@"score"] = score.description;

                        [topScores addObject:entry];
                    }

                    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray: topScores];


                }
            [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
        }];
    }
}
然后进入staging/www/plugins/cordova plugin gamecenter/www/gamecenter.js

GameCenter.prototype.getScores = function (success, failure, data) {
exec(success, failure, "GameCenter", "getScores", [data]);
})

下一步就是在游戏中调用函数:

function getHighScores(){
    console.log('gethighscores');

    var successCallback = function(data){
        console.log(success);
    }


    var failureCallback = function (data) {
        console.log('Fail');
    }

    var data = { leaderboardId: "escapemtl" }

    gamecenter.getScores(successCallback, failureCallback, data);}

如果我调用该函数,控制台中不会发生任何事情,因此在一整天之后,我完成了以下工作:

插入:

  GKPlayer* player = score.player;
                    NSMutableDictionary *entry = [NSMutableDictionary dictionary];
                    entry[@"score"] = [NSNumber numberWithLongLong:(score.value) ];
                    entry[@"name"] = player.alias;
                    [topScores addObject:entry];
进入:

 for (GKScore* score in scores)
                {


                    NSMutableDictionary *entry = [NSMutableDictionary dictionary];
                    entry[@"score"] = score.description;

                    [topScores addObject:entry];
                }