Class

GKMatch

A GKMatch object provides a peer-to-peer network between a group of devices that are connected to Game Center. Matches provide transmit both voice and game data. Your game never directly allocates GKMatch objects. Instead, it uses the GKMatchmaker class to programmatically find a match with other interested players or a GKMatchmaker​View​Controller object to display a user interface to the player.

Overview

After your game receives a match object, set its delegate and then wait until the other participants are connected to the match. You can read the expected​Player​Count property to determine how many players have not connected to the match.

Each device in the match is identified by the player identifier for the player authenticated on that device. Your game transmits its own data to other players by calling either the send​Data(to​All​Players:​with:​) method or the send(_:​to​Players:​with:​) method. To allow voice chat, call voice​Chat(with​Name:​) to create one or more voice channels.

When you are finished with the match, call the match’s disconnect() method. Before you release your last reference to a GKMatch object, make sure you set the delegate back to nil. Otherwise a match you thought was long gone can suddenly call match(_:​player:​did​Change:​) when you are in the middle of the next game.

Symbols

Getting and Setting the Delegate

var delegate:​ GKMatch​Delegate?

The delegate for the match.

Working with Other Players

var expected​Player​Count:​ Int

The remaining number of players who have not yet connected to the match.

var players:​ [GKPlayer]

An array of GKPlayer objects that represent the players in the match.

Sending Data to Other Players

func choose​Best​Hosting​Player(completion​Handler:​ (GKPlayer?) -> Void)

Determines the best player in the game to act as the server for a client-server match.

GKMatch​Send​Data​Mode

The mechanism used to transmit data to other players.

Joining a Voice Chat

Finishing the Match

func disconnect()

Disconnects the local player from the match.

func rematch(completion​Handler:​ ((GKMatch?, Error?) -> Void)? = nil)

Create a new match with the list of players from an existing match.

Deprecated Methods and Properties

func choose​Best​Host​Player(completion​Handler:​ (String?) -> Void)

Determines the best player in the game to act as the server for a client-server match.

Deprecated
var player​IDs:​ [String]

An array of NSString objects containing the player identifiers for remote players in the match.

Deprecated
func send(Data, to​Players:​ [String], with:​ GKMatch​Send​Data​Mode)

Transmits data to a list of connected players.

Deprecated

Relationships

Inherits From

See Also

Related Documentation