在他们的支持中OpenFeint给你这个,但我不太明白。我怎样才能获得排行榜数据,比如前10名并在我自己的用户界面中显示?
原始链接: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
{
highscores = page.objects;
}
}
for (OFHighScore* score in highscores)
{
// ...
}
}
- (BOOL)canReceiveCallbacksNow
{
return YES;
}
答案 0 :(得分:2)
请求高分页面的代码是第一行,即:
[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];
您将此行放在要开始查询以获得高分的位置。您可以根据需要更改页码。一旦检索到高分页面,就会调用回调_scoresDownloaded
。该示例显示了如何遍历OFHighScore
数组中的highscores
个对象。您可以使用自己的代码替换评论// ...
,以向玩家显示分数,或者其他任何内容。
(如果调用错误_failedDownloadingScores
;您应该实现它以显示错误。)