Contents

loadFriends(_:)

Loads the local player’s friends list if the local player and their friends grant access.

Declaration

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

Parameters

  • 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.

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

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

    error

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

Mentioned in

Discussion

If the loadFriendsAuthorizationStatus(_:) method returns GKFriendsAuthorizationStatus.notDetermined, GameKit presents a prompt to the local player requesting access to their 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