Game Development Reference
In-Depth Information
Once the call to loadFriendsWithCompletionHandler has succeeded, you
can access the current player identifiers of the local player's friends through the
GKLocalPlayer class:
NSArray* friends = GKLocalPlayer.localPlayer.friends;
Note that the friends array can be nil or not contain all friends. In the delegate that
receives the onFriendsListReceived message, and in all other
GameKitHelper delegate methods for that matter, you should check whether the re-
ceived parameter is nil before working with it. If it's nil , you can refer to the
lastError property of the GameKitHelper class to get more information about
the error for debugging, logging, or possibly presenting it to the user when it makes
sense to do so.
The delegate method onFriendsListReceived simply passes the player identifi-
ers back to GameKitHelper , requesting more info about the player identifiers in the
friends list:
-(void) onFriendListReceived:(NSArray*)friends
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getPlayerInfo:friends];
That's straightforward, so let's turn our attention back to the GameKitHelper class's
getPlayerInfo method. If the playerList array contains at least one entry, it
will call the loadPlayersForIdentifiers static method of the GKPlayer
class, as shown in Listing 14-8 .
Listing 14-8 . Requesting Players from a List of Player Identifiers
-(void) getPlayerInfo:(NSArray*)playerList
if (playerList.count > 0)
// Get detailed information about a list of players
[GKPlayer loadPlayersForIdentifiers:playerList withCompletionHandler:←
^(NSArray* players, NSError* error)
Search Nedrilad ::

Custom Search