A set of parameters for a new live or turn-based match.
- iOS 4.1+
- macOS 10.8+
- tvOS 9.0+
- watchOS 3.0+
Initialize a match request object and pass it to another object to actually create the match. The type of object you pass it to depends on the type of match you want and whether you want to display the standard matchmaking user interface. See Table 1.
When creating a match request, you are required to set the minimum and maximum players allowed for the match. Listing 1 shows a simple match request with the minimum, maximum, and default number of players set to 2.
If you are implementing a complete custom user interface, you need to allow players to invite their friends to a match. Typically, this means that your game presents an interface that shows all the players currently in the match, with empty slots for positions to be filled. A player can then pick one or more of those empty slots and issue an invitation to a specific player. To accomplish this, your game needs to be able to send the invitations and receive notifications when the invitations are processed.
You handle both of these problems by assigning more information to the match request. You need to assign a list of players to invite and an invitee handler. As each invitation is processed, your handler is called. Listing 2 shows a typical implementation of the match request to handle this. In this example, a match request is created and a list of player identifiers is assigned to the request. Also, this code provides a custom invitation message; in your game, you should allow the player to customize this message.
When a response is received, if the response is equal to
GKInvitee, the player is added to the match. In this case, the user interface code (not shown here) is updated to show that this player is now part of the match. If any other response is received, the player is removed from the user interface so that the slot appears empty again. Optionally, a more sophisticated example might display a specific error message to the player detailing why the invitation was not accepted; see
GKMatch for details.