Instance Method

loadFriendPlayers(completionHandler:)

Retrieves a list of player identifiers for the local player’s friends.

Declaration

func loadFriendPlayers(completionHandler: (([GKPlayer]?, Error?) -> Void)? = nil)

Parameters

completionHandler

A block to be called when the request completes.

The block receives the following parameters:

friendPlayers

An array of GKPlayer objects containing the player identifiers for the players that are friends of the local player. If an error occurred, this value can be non-nil. In that case, the array contains the data that Game Kit was able to download before the error occurred.

error

If an error occurred, this parameter holds an error object that explains the error. Otherwise, the value of this parameter is nil.

Discussion

Listing 1 shows an example of how to load a player’s friends. Create your own method to save information about the found players.

Listing 1

Retrieving a local player’s friends

- (void) retrieveFriends
{
   GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
   if (lp.authenticated)
   {
      [lp loadFriendPlayersWithCompletionHandler:^(NSArray *friendPlayers, NSError *error) {
         if (friendPlayers != nil)
         {
            [self loadPlayerData: friendPlayers];
         }
      }];
   }
}

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread.

See Also

Deprecated Methods and Properties

func authenticate(completionHandler: ((Error?) -> Void)?)

Authenticates the local player on the device.

Deprecated
var friends: [String]?

An array of NSString objects containing the player identifiers for the local player’s friends.

Deprecated
func loadDefaultLeaderboardCategoryID(completionHandler: ((String?, Error?) -> Void)?)

Loads the category identifier for the local player’s default leaderboard.

Deprecated
func loadFriends(completionHandler: (([String]?, Error?) -> Void)?)

Retrieves a list of player identifiers for the local player’s friends.

Deprecated
func setDefaultLeaderboardCategoryID(String?, completionHandler: ((Error?) -> Void)?)

Sets the category identifier for the local player’s default leaderboard.

Deprecated