Contents

loadFriendPlayers(completionHandler:)

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

Declaration

func loadFriendPlayers(completionHandler: (@Sendable ([GKPlayer]?, (any Error)?) -> Void)? = nil)
func loadFriendPlayers() async throws -> [GKPlayer]

Parameters

  • completionHandler:

    A block to call when the request completes.

    The block receives the following parameters:

    friendPlayers

    An array of Gkplayer objects containing the player identifiers for the players who are friends of the local player. If an error occurs, this value can be non-nil. In that case, the array contains the data that GameKit downloads before the error occurs.

    error

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

Discussion

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

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

See Also

Deprecated methods