The GKMatchmaker class is used to programmatically create matches to other players and to receive match invitations sent by other players.


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 inviteHandler 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 GKMatchRequest object that describes the match you are interested in. Then, call the shared matchmaker’s findMatch(for:withCompletionHandler:) method to create a peer-to-peer match, or its findPlayers(forHostedMatchRequest:withCompletionHandler:) 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 addPlayers(to:matchRequest:completionHandler:) method to add more participants to the match. Once the match is complete, call the finishMatchmaking(for:) 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.


Retrieving the Shared Matchmaker

class func shared()

Returns the singleton matchmaker instance.

Receiving Invitations From Other Players

Matching Players

func cancel()

Cancels a pending matchmaking request.

func cancelPendingInvite(to: GKPlayer)

Cancels a pending invitation to another player.

func finishMatchmaking(for: GKMatch)

Informs Game Center that programmatic matchmaking has finished.

func queryActivity(completionHandler: ((Int, Error?) -> Void)? = nil)

Initiates a search for activity in all player groups.

func cancelInvite(toPlayer: String)

Cancels a pending invitation to another player.


Looking For Nearby Players

func startBrowsingForNearbyPlayers(handler: ((GKPlayer, Bool) -> Void)? = nil)

Enables the matchmaking process to find nearby players through Bluetooth or WiFi (same subnet only).

func stopBrowsingForNearbyPlayers()

Ends the search for nearby players.

func startBrowsingForNearbyPlayers(reachableHandler: ((String, Bool) -> Void)? = nil)

Enables the matchmaking process to find nearby players through Bluetooth or WiFi (same subnet only).



Inherits From

Conforms To