Protocol: GKMatchDelegate

Overview

The GKMatchDelegate protocol is implemented to receive status updates and network data from players connected to a GKMatch object.Called when the match cannot connect to any other players.Called when data is received from a player. (required)Called when a player connects to or disconnects from the match.Called when a player in a two-player match was disconnected.The state of another player in the match.

Instance Method Summary (collapse)

Instance Method Details

- (Object) match(match, didFailWithError:error)

Called when the match cannot connect to any other players. 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.

Parameters:

  • match (GKMatch)

    The match that received the error.

  • error (NSError)

    The error that occurred.

Returns:

- (Object) match(match, didReceiveData:data, fromPlayer:playerID)

Called when data is received from a player. (required) Your game defines its own format for data packets it transmits and receives over the network.Important:  Data received from other players should be treated as untrusted data. Be sure to validate the data you receive from the match and write your code carefully to avoid security vulnerabilities. See the Secure Coding Guide for more information.

Parameters:

  • match (GKMatch)

    The match that received the data.

  • data (NSData)

    The bytes sent by the player.

  • player (String)

    The string identifier for the player that sent the data.

Returns:

- (Object) match(match, player:playerID, didChangeState:state)

Called when a player connects to or disconnects from the match. Your game implements this method to be notified when players connect to or disconnect from the match.

Parameters:

  • match (GKMatch)

    The match that the player is connected to.

  • player (String)

    The identifier for the player whose state changed.

  • state (GKPlayerConnectionState)

    The state the player moved to.

Returns:

- (Boolean) match(match, shouldReinvitePlayer:playerID)

Called when a player in a two-player match was disconnected. 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.

Parameters:

  • match (GKMatch)

    The match that lost the player.

  • playerID (String)

    The identifier for the player whose connection failed.

Returns:

  • (Boolean)

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