Skip to content

Commit

Permalink
Get Data
Browse files Browse the repository at this point in the history
  • Loading branch information
maximo72 committed Nov 22, 2019
1 parent ffcc077 commit 5537f44
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ios/GameCenter.h
Expand Up @@ -17,5 +17,6 @@
- (void) reportAchievement:(CDVInvokedUrlCommand*)command;
- (void) resetAchievements:(CDVInvokedUrlCommand*)command;
- (void) getAchievements:(CDVInvokedUrlCommand*)command;
- (void) getScore:(CDVInvokedUrlCommand*)command;

@end
27 changes: 27 additions & 0 deletions src/ios/GameCenter.m
Expand Up @@ -265,4 +265,31 @@ - (void) getAchievements:(CDVInvokedUrlCommand*)command;
}];
}

- (void) getScore:(CDVInvokedUrlCommand*)command
{
__block CDVPluginResult* pluginResult = nil;
NSMutableDictionary *args = [command.arguments objectAtIndex:0];
NSString *leaderboardId = [args objectForKey:@"leaderboardId"];

GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
leaderboardRequest.identifier = leaderboardId;

[leaderboardRequest loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {
if (error) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
} else if (scores) {
GKScore *localPlayerScore = leaderboardRequest.localPlayerScore;

NSDictionary* userScore = @{
@"score": [NSNumber numberWithLongLong:localPlayerScore.value]
};
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userScore];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

@end
4 changes: 4 additions & 0 deletions www/gamecenter.js
Expand Up @@ -33,4 +33,8 @@ GameCenter.prototype.getAchievements = function (success, failure) {
exec(success, failure, "GameCenter", "getAchievements", []);
};

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

module.exports = new GameCenter();

0 comments on commit 5537f44

Please sign in to comment.