GKMatchmaker
An object that creates matches with other players without presenting an interface to the players.
Declaration
class GKMatchmakerMentioned in
Overview
Use the GKMatchmaker class to auto-match players for a quicker game start, programmatically invite specific players, or implement your own interface for players to invite other players. If you want to present a familiar matchmaking GameKit interface to players, instead use either the GKMatchmakerViewController or GKTurnBasedMatchmakerViewController class.
If you host a game on your own server, you can also use this class to find Game Center players. That is, you implement the networking and communication between the players through your own servers not Game Center.
To find players using this class, create a GKMatchRequest object and configure it according to the parameters of your game. Then, pass the match request and a handler using the findMatch(for:withCompletionHandler:) method, or the findPlayers(forHostedMatchRequest:withCompletionHandler:) method for hosted games, to the shared GKMatchmaker object.
GameKit calls the handler when players accept their invitations. Implement the handler to set the delegate of the GKMatch object that GameKit sends and start the game when there are enough players.
If the match doesn’t have enough players (for example, some players decline their invitations), you can create another match request and call the addPlayers(to:matchRequest:completionHandler:) method repeatedly until the match’s expectedPlayerCount property is zero. When you have enough players to start the match, call the finishMatchmaking(for:) method to end the matchmaking process.
If you provide a SharePlay interface for inviting players, use the startGroupActivity(playerHandler:) and stopGroupActivity() methods to create a group activity on behalf of the player.
Topics
Retrieving the shared matchmaker
Receiving invitations from other players
Matching players
findMatch(for:withCompletionHandler:)findPlayers(forHostedRequest:withCompletionHandler:)findMatchedPlayers(_:withCompletionHandler:)GKMatchedPlayersaddPlayers(to:matchRequest:completionHandler:)finishMatchmaking(for:)cancel()cancelPendingInvite(to:)
Finding players who request matches
queryActivity(completionHandler:)queryPlayerGroupActivity(_:withCompletionHandler:)queryQueueActivity(_:withCompletionHandler:)