An object that programmatically creates matches with other players and receives match invitations sent by other players.
SDKs
- iOS 4.1+
- macOS 10.8+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Game
Kit
Declaration
@interface GKMatchmaker : NSObject
Overview
Important
Your game must authenticate a local player before you can use any Game Center classes. If there is no authenticated player, your game receives a GKError
error. For more information on authentication, see Game Center Programming Guide.
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.
Note
Hosted matches are intended for developers who already have a networking game service but who want to use Game Center to find players for a match. Because you need to design and implement your own networking code, you can define your own protocols to connect to your server.
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 finish
method.
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.