Contents

loadFriends(identifiedBy:completionHandler:)

Loads the player’s friends list, scoped by the identifiers, if the player and their friends grant access.

Declaration

func loadFriends(identifiedBy identifiers: [String], completionHandler: @escaping  @Sendable ([GKPlayer]?, (any Error)?) -> Void)
func loadFriends(identifiedBy identifiers: [String]) async throws -> [GKPlayer]

Parameters

  • identifiers:

    The game player IDs and team player IDs that GameKit uses to scope the friends that it passes to the completion handler.

  • completionHandler:

    The block that GameKit calls when it completes the request.

    The block receives the following parameters:

    friends

    The player’s friends who also grant your game access to their friends and whose Gameplayerid or Teamplayerid property appears in the identifiers parameter.

    The local player and their friends’ authorization status must be Authorized.

    The local player and their friends must use a version of the game with the same bundle ID.

    error

    Describes an error if it occurs, or nil if the operation completes.

Discussion

If the loadFriendsAuthorizationStatus(_:) method returns GKFriendsAuthorizationStatus.notDetermined, GameKit presents a prompt to the local player requesting access to the friends that may pause your game. GameKit displays the localized reason that you provide for the NSGKFriendListUsageDescription key in the information property list.

If you loaded friends who no longer appear in the friends parameter of the completion handler, remove the data for those friends from your game because they no longer grant your game access to that data.

See Also

Accessing Friends and Recents