GKMatch
A peer-to-peer network between a group of players that sign into Game Center.
Declaration
class GKMatchMentioned in
Overview
Matches provide a mechanism for a player to send both game and voice data to other players.
You never create a GKMatch object directly. Instead, GameKit passes a match object to a GKMatchmakerViewControllerDelegate method or a GKMatchmaker handler when you set up a multiplayer game. For details, see Finding multiple players for a game.
If you use the GKMatchmakerViewController class to find players, implement the matchmakerViewController(_:didFind:) delegate method to set the match delegate. If you use the GKMatchmaker class, set the match delegate in the handler you pass to the findMatch(for:withCompletionHandler:) method.
You can begin exchanging data when two or more players join the match. Implement the match(_:player:didChange:) delegate method to track when players connect or disconnect from the match. Then use either the sendData(toAllPlayers:with:) or the send(_:to:dataMode:) method to send data. To process the data on the recipient side, implement the match(_:didReceive:fromRemotePlayer:) delegate method.
To implement voice chat, use the voiceChat(withName:) method to create one or more voice channels represented by the returned GKVoiceChat object.
When you’re finished with a match, call the disconnect() method and set the match’s delegate to nil. Otherwise, GameKit may send match(_:player:didChange:) to the delegate until all players disconnect from the match.
Topics
Setting the delegate
Working with other players
Sending data to other players
chooseBestHostingPlayer(completionHandler:)send(_:to:dataMode:)sendData(toAllPlayers:with:)GKMatch.SendDataMode