Game Development Reference
if ([delegate respondsToSelector:@selector(onScoresReceived:)])
First, a GKLeaderboard object is initialized. Depending on whether the players
array contains any players, the leaderboard may be initialized with a list of player iden-
tifiers to retrieve scores only for those players. Otherwise, the playerScope variable
is used, which can be set to either GKLeaderboardPlayerScopeGlobal or
GKLeaderboardPlayerScoreFriendsOnly to retrieve only friends' scores.
Then the leaderboard scope is further reduced by the timeScope parameter, which
allows you to obtain the all-time high scores ( GKLeaderboardTimeS-
copeAllTime ), only those from the past week ( GKLeaderboardTimeS-
copeWeek ), or only today's scores ( GKLeaderboardTimeScopeToday ).
Of course, you also have to specify the category ID for the leaderboard—otherwise,
GKLeaderboard wouldn't know which leaderboard to retrieve the scores from. Fin-
ally, an NSRange parameter lets you refine the score positions you'd like to retrieve.
In this example, a range of 1 to 10 indicates that the top ten scores should be retrieved.
Make sure you limit the score retrieval using all these parameters (especially the
NSRange parameter) to reasonably small chunks of data. Although you could, it's not
recommended to retrieve all the scores of a leaderboard. If your game is played online
a lot, and many scores are submitted, you might be loading hundreds of thousands—if
not millions or billions—of scores from the Game Center servers. That would cause a
significant delay when retrieving scores.
With the leaderboard object set up properly, the loadScoresWithComple-
tionHandler method takes over and asks the server for the scores. When the scores
are received, it calls the delegate method with onScoresReceived , passing on the
array of scores. The array contains objects of class GKScore sorted by leaderboard
rank. The GKScore objects provide you with all the information you need, including