Game Development Reference
In-Depth Information
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper getLocalPlayerFriends];
It checks whether the local player is authenticated, and if so, it calls the
getLocalPlayerFriends method of the GameKitHelper class right away.
Take a look at that in Listing 14-7 .
Listing 14-7 . GameKitHelper Requesting the Friends List
-(void) getLocalPlayerFriends
if (isGameCenterAvailable == NO)
GKLocalPlayer* localPlayer = GKLocalPlayer.localPlayer;
if (localPlayer.authenticated)
[localPlayer loadFriendsWithCompletionHandler:←
^(NSArray* friends, NSError* error)
[self setLastError:error];
if ([delegate respondsToSelector:@selector(onFriendListReceived:)])
[delegate onFriendListReceived:friends];
Because the getLocalPlayerFriends method doesn't know when it's called or
by whom, it plays things safe by checking again that the local player is actually authen-
ticated. Then it calls the GKLocalPlayer class's loadFriendsWithComple-
tionHandler method, for which you'll supply another block object that's run when
the server returns a list of player identifiers as strings. Unsurprisingly, this list of identi-
fiers is stored in the friends array.
Search Nedrilad ::

Custom Search