iOS Developer Library

Developer

GameKit Framework Reference GKTurnBasedEventListener Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKTurnBasedEventListener

Inherits From


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in iOS 7.0 and later

Handles events for turn-based games. Provides methods for responding to exchanges and match events.

Do not implement GKTurnBasedEventListener directly, instead use GKLocalPlayerListener. The GKLocalPlayerListener protocol inherits methods from GKTurnBasedEventListener, GKInviteEventListener, and GKChallengeListener in order to handle multiple events.

  • Called when the exchange is cancelled by the sender. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, receivedExchangeCancellation exchange: GKTurnBasedExchange!, forMatch match: GKTurnBasedMatch!)

    Objective-C

    - (void)player:(GKPlayer *)player receivedExchangeCancellation:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    exchange

    A GKTurnBasedExchange object containing the exchange that is cancelled.

    match

    The GKTurnBasedMatch object containing the current match information.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

  • Called when the exchange is completed. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, receivedExchangeReplies replies: [AnyObject]!, forCompletedExchange exchange: GKTurnBasedExchange!, forMatch match: GKTurnBasedMatch!)

    Objective-C

    - (void)player:(GKPlayer *)player receivedExchangeReplies:(NSArray *)replies forCompletedExchange:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    replies

    An array of GKTurnBasedExchange objects containing the replies from other players.

    exchange

    A GKTurnBasedExchange object containing the exchange that is completed.

    match

    The GKTurnBasedMatch object containing the current game data.

    Discussion

    This method is called when all of the players have either responded to the exchange or timed-out. The result is then sent to the current player and the initiator of the exchange.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

  • Called when a player receives an exchange request from another player. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, receivedExchangeRequest exchange: GKTurnBasedExchange!, forMatch match: GKTurnBasedMatch!)

    Objective-C

    - (void)player:(GKPlayer *)player receivedExchangeRequest:(GKTurnBasedExchange *)exchange forMatch:(GKTurnBasedMatch *)match

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    exchange

    A GKTurnBasedExchange object containing the requested exchange.

    match

    The GKTurnBasedMatch object containing the current game data.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

  • Initiates a match from Game Center with the requested players. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, didRequestMatchWithOtherPlayers playersToInvite: [AnyObject]!)

    Objective-C

    - (void)player:(GKPlayer *)player didRequestMatchWithOtherPlayers:(NSArray *)playersToInvite

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    playersToInvite

    An array of GKPlayer objects containing the player identifiers to invite to the match.

    Discussion

    When this method is called, you should create a new match using the player identifiers provided and present a GKTurnBasedMatchmakerViewController.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 8.0 and later

  • Called when the match has ended. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, matchEnded match: GKTurnBasedMatch!)

    Objective-C

    - (void)player:(GKPlayer *)player matchEnded:(GKTurnBasedMatch *)match

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    match

    The GKTurnBasedMatch object containing the current game data.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

  • Activates the player’s turn. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, receivedTurnEventForMatch match: GKTurnBasedMatch!, didBecomeActive didBecomeActive: Bool)

    Objective-C

    - (void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    match

    The GKTurnBasedMatch object containing the current game data.

    didBecomeActive

    Denotes whether the app should be launched or brought to the foreground.

    Discussion

    This method is called when the it becomes the player’s turn. It is also called when any of the following events happen:

    • The current turn has a time-out associated with it and the turn is about to expire.

    • Player accepts an invite from another player.

    • Turn was passed to another player. In this case, didBecomeActive is false.

    • Match data is saved by another player.

    • Player receives a reminder.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

  • Initiates a match from Game Center with the requested players. (required)

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, didRequestMatchWithPlayers playerIDsToInvite: [AnyObject]!)

    Objective-C

    - (void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite

    Parameters

    player

    The GKPlayer object containing the current player’s information.

    playerIDsToInvite

    An array of NSString objects containing the player identifiers to invite to the match.

    Discussion

    When this method is called, you should create a new match using the player identifiers provided and present a GKTurnBasedMatchmakerViewController.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 7.0 and later

    Deprecated in iOS 8.0