An object that programmatically creates matches with other players and receives match invitations sent by other players.
- iOS 4.1+
- macOS 10.8+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
Matches can be either peer-to-peer or hosted. A peer-to-peer match is fully supported in Game Kit by the
GKMatch class. A
GKMatch object provides all of the network connections between the devices and routes the network data through Game Center if necessary. In contrast, a hosted match uses matchmaking to find the players for a match, but your game implements its own networking between the participants, routing through your own server if necessary.
To receive invitations from other players, your game must provide an invitation handler. After your game successfully authenticates the local player, it should immediately set the
invite property. The invite handler is called immediately if your game was launched in response to a push notification.
To programmatically search for other players, start by creating a
GKMatch object that describes the match you are interested in. Then, call the shared matchmaker’s
find method to create a peer-to-peer match, or its
find method to create a hosted match. In either case, Game Center matches players into a match and calls your completion handler. If the match does not have enough players (for example, you invited a specific list of players and some declined the invitation), you can create another match request and call the
add method to add more participants to the match. Once the match is complete, call the
If you implement programmatic matchmaking and invite specific players to the match, you should also implement an invitee response handler. This handler is notified as invitations are processed, allowing you to update your game’s custom user interface to display which players are connected to the match.