Mac Developer Library

Developer

GameKit Framework Reference GKMatchDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKMatchDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in OS X v10.8 and later.

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

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

    Declaration

    Swift

    optional func match(_ match: GKMatch!, didReceiveData data: NSData!, fromRemotePlayer player: GKPlayer!)

    Objective-C

    - (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromRemotePlayer:(GKPlayer *)player

    Parameters

    match

    The GKMatch object that received the data.

    data

    The bytes sent by the player.

    player

    The GKPlayer object identifying the player that sent the data.

    Discussion

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

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.

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

    Declaration

    Swift

    optional func match(_ match: GKMatch!, didReceiveData data: NSData!, fromPlayer player: String!)

    Objective-C

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

    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.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Called when a player connects to or disconnects from the match. (required)

    Declaration

    Swift

    optional func match(_ match: GKMatch!, player player: GKPlayer!, didChangeConnectionState state: GKPlayerConnectionState)

    Objective-C

    - (void)match:(GKMatch *)match player:(GKPlayer *)player didChangeConnectionState:(GKPlayerConnectionState)state

    Parameters

    match

    The GKMatch object identifying the match the player is connected to.

    player

    The GKPlayer object that identifying the player whose state has changed.

    state

    The GKPlayerConnectionState that the player has moved to.

    Discussion

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

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Objective-C

    - (void)match:(GKMatch *)match player:(NSString *)player 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.

    Import Statement

    Objective-C

    @import GameKit;

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.8.

  • Called when the match cannot connect to any other players.

    Declaration

    Swift

    optional func match(_ match: GKMatch!, didFailWithError error: NSError!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • Called when a player in a two-player match was disconnected. (required)

    Declaration

    Swift

    optional func match(_ match: GKMatch!, shouldReinviteDisconnectedPlayer player: GKPlayer!) -> Bool

    Objective-C

    - (BOOL)match:(GKMatch *)match shouldReinviteDisconnectedPlayer:(GKPlayer *)player

    Parameters

    match

    The GKMatch object that lost the player.

    player

    The GKPlayer object identifying the player whose connection failed.

    Return Value

    Your game should return YEStrue if it wants Game Kit to attempt to reconnect the player, NOfalse 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:didChangeConnectionState: method is called when the other player is reconnected.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.

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

    Declaration

    Swift

    optional func match(_ match: GKMatch!, shouldReinvitePlayer playerID: String!) -> Bool

    Objective-C

    - (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 YEStrue if it wants Game Kit to attempt to reconnect the player, NOfalse 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.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

Data Types

  • The state of another player in the match.

    Declaration

    Swift

    enum GKPlayerConnectionState : Int { case StateUnknown case StateConnected case StateDisconnected }

    Objective-C

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

    Constants

    • StateUnknown

      GKPlayerStateUnknown

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

      Available in OS X v10.8 and later.

    • StateConnected

      GKPlayerStateConnected

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

      Available in OS X v10.8 and later.

    • StateDisconnected

      GKPlayerStateDisconnected

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

      Available in OS X v10.8 and later.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.