GKMatchDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/GameKit.framework
Availability
Available in OS X v10.8 and later.
Companion guide
Declared in
GKMatch.h

Overview

The GKMatchDelegate protocol is implemented to receive status updates and network data from players connected to a GKMatch object.

Tasks

Receiving Data from Other Players

Receiving State Notifications About Other Players

Handling Errors

Reinviting a Player

Instance Methods

match:didFailWithError:

Called when the match cannot connect to any other players.

- (void)match:(GKMatch *)match didFailWithError:(NSError *)error
Parameters
match

The match that received the error.

error

The error that occurred.

Discussion

This method is called if the match cannot connect to any other players associated with the match. It usually means a serious networking error has occurred.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKMatch.h

match:didReceiveData:fromPlayer:

Called when data is received from a player. (required)

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
Parameters
match

The match that received the data.

data

The bytes sent by the player.

player

The string identifier for the player that sent the data.

Discussion

Your game defines its own format for data packets it transmits and receives over the network.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKMatch.h

match:player:didChangeState:

Called when a player connects to or disconnects from the match.

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
Parameters
match

The match that the player is connected to.

player

The identifier for the player whose state changed.

state

The state the player moved to.

Discussion

Your game implements this method to be notified when players connect to or disconnect from the match.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKMatch.h

match:shouldReinvitePlayer:

Called when a player in a two-player match was disconnected.

- (BOOL)match:(GKMatch *)match shouldReinvitePlayer:(NSString *)playerID
Parameters
match

The match that lost the player.

playerID

The identifier for the player whose connection failed.

Return Value

Your game should return YES if it wants Game Kit to attempt to reconnect the player, NO if it wants to terminate the match.

Discussion

Occasionally, players may get disconnected from a match. If your game implements this method in the match delegate and the match only contains two players, Game Kit calls this method after a player gets disconnected. If your delegate allows Game Kit to reconnect to the other player, it reconnects the other player. Your match:player:didChangeState: method is called when the other player is reconnected.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKMatch.h

Constants

Player Connection States

The state of another player in the match.

enum {
   GKPlayerStateUnknown,
   GKPlayerStateConnected,
   GKPlayerStateDisconnected
};
typedef NSInteger GKPlayerConnectionState;
Constants
GKPlayerStateUnknown

The player is in an indeterminate state and cannot receive data.

Available in OS X v10.8 and later.

Declared in GKMatch.h.

GKPlayerStateConnected

The player is connected to the match and can receive data.

Available in OS X v10.8 and later.

Declared in GKMatch.h.

GKPlayerStateDisconnected

The player is disconnected from the match and cannot receive data.

Available in OS X v10.8 and later.

Declared in GKMatch.h.

Availability
  • Available in OS X v10.8 and later.
Declared In
GKMatch.h