Reputation: 31
For a single gamecenter leaderboard I want to get a total of all scores uploaded within the last week.
Currently I query the leaderboard with a start of 0 and range of 100, fetch the scores, add those scores to a running total, fetch another 100 with a new start at 100, add those to the running total; keep doing this until gamecenter returns no scores.
This works but it is not efficient as the multiple fetches to the leaderboards takes quite a bit of time. I am hoping there is a total stored somewhere on the gamecenter server that I can access directly.
The following is one call to gamecenter and totaling all of those scores
NSInteger scorePercent = 0;
localLeaderboard.range = NSMakeRange(rangestart, 100);
[localLeaderboard loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil) {
NSLog(@"leadboard loadScores returned error = %@", error);
// handle the error. if (scores != nil)
}
if (scores != nil){
// process the score information..
NSInteger numScores = localLeaderboard.maxRange; // number of leaderboard entries returned.
for (NSInteger nscores=0; nscores < numScores; nscores++ ) {
scorePercent += ((GKScore*) scores[nscores]).value;
}
scoreTotal += scorePercent // aggregate for later percentage calculations
}
}];
Current method works but is not efficient.
Upvotes: 3
Views: 90