Class

GKMatch

A peer-to-peer network between a group of devices that are connected to Game Center.

Declaration

@interface GKMatch : NSObject

Overview

Matches provide transmittal of 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 GKMatchmakerViewController object to display a user interface to the player.

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 expectedPlayerCount 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 sendDataToAllPlayers:withDataMode:error: method or the sendData:toPlayers:withDataMode:error: method. To allow voice chat, call voiceChatWithName: 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:didChangeState: when you are in the middle of the next game.

Topics

Getting and Setting the Delegate

delegate

The delegate for the match.

GKMatchDelegate

The delegate is called when status updates and network data is received from players.

Working with Other Players

expectedPlayerCount

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

players

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

Sending Data to Other Players

- chooseBestHostingPlayerWithCompletionHandler:

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

- sendData:toPlayers:dataMode:error:

Transmits data to a list of connected players.

- sendDataToAllPlayers:withDataMode:error:

Transmits data to all players connected to the match.

GKMatchSendDataMode

The mechanism used to transmit data to other players.

Joining a Voice Chat

- voiceChatWithName:

Joins a voice channel.

Finishing the Match

- disconnect

Disconnects the local player from the match.

- rematchWithCompletionHandler:

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

Deprecated Methods and Properties

- chooseBestHostPlayerWithCompletionHandler:

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

Deprecated
playerIDs

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

Deprecated
- sendData:toPlayers:withDataMode:error:

Transmits data to a list of connected players.

Deprecated

Relationships

Inherits From

See Also

Real-Time Matches

GKMatchRequest

A set of parameters for a new live or turn-based match.

GKVoiceChat

A voice channel that allows a set of players in a match to speak with each other.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software