Your game uses the
GKFriend class to present a screen that allows the local player to send friend requests to other players.
- iOS 4.2–10.0Deprecated
- macOS 10.8–10.12Deprecated
- Mac Catalyst 13.0–13.0Deprecated
To show a friend request, initialize a new
GKFriend object and set the delegate. Optionally, you can customize the request by adding a text message or a list of recipients. Then, present the new view controller and wait for the delegate to be called. Once the delegate is called, dismiss the view controller.
On iOS, you present and dismiss the view controller from another view controller in your game, using the methods provided by the
UIView class. In macOS, you use the
GKDialog class to present and dismiss the view controller. Listing 1 shows one way your view controller can allow a player to send a request to other players. For this method, an array of
GKPlayer objects is passed in as a parameter. The method instantiates a
GKFriend object, sets its delegate, and adds the list of players intended to receive the invitation. The view controller then presents the friend request and returns.
GKFriend class is not intended to be subclassed.