How to get high scores from OpenFeint?
In their support OpenFeint give you this, but I don't quite understand. How can I get the leaderboard data, say top 10 and show it in my own UI?
Original link: http://www.openfeint.com/ofdeveloper/index.php/kb/article/000028
[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];
- (void)_scoresDownloaded:(OFPaginatedSeries*)page
{
NSMutableArray* highscores = nil;
if ([page count] > 0)
{
if ([[page objectAtIndex:0] isKindOfClass:[OFTableSectionDescription class]])
{
// NOTE: In the following line, we access "[page objectAtIndex:1]" to retrieve high scores from
// the global leaderboard. Using "[page objectAtIndex:0]" would retrieve scores just for the local player.
// Older versions of OpenFeint did not break this out into 2 sections.
highscores = [(OFTableSectionDescription*)[page objectAtIndex:1] page].objects;
}
else
开发者_StackOverflow中文版 {
highscores = page.objects;
}
}
for (OFHighScore* score in highscores)
{
// ...
}
}
- (BOOL)canReceiveCallbacksNow
{
return YES;
}
The code to request a page of high scores is the first line, i.e.:
[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];
You put this line in the place where you want to start the query for high scores. You can change the page number as required. Once the page of high scores has been retrieved, the callback _scoresDownloaded
is called. The example shows you how you would iterate through the OFHighScore
objects in the highscores
array. You would replace the comment // ...
with your own code to show the scores to the player, or whatever.
(In case of error _failedDownloadingScores
is called; you should implement that to show an error.)
精彩评论