Mac Developer Library

Developer

GameKit Framework Reference GKChallengeListener Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKChallengeListener

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in OS X v10.10 and later.

Provides methods for responding to challenge events. Your app can ignore a challenge, start up in a specific state so the player can respond to a challenge, or notify the original challenger when the local player completes a challenge.

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

  • Called when a player receives a challenge and doesn’t want to address it immediately.

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, didReceiveChallenge challenge: GKChallenge!)

    Objective-C

    - (void)player:(GKPlayer *)player didReceiveChallenge:(GKChallenge *)challenge

    Parameters

    player

    The player that receives the challenge.

    challenge

    The challenge sent to the player.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • Called when a player wants to start a game with the intention of completing a challenge.

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, wantsToPlayChallenge challenge: GKChallenge!)

    Objective-C

    - (void)player:(GKPlayer *)player wantsToPlayChallenge:(GKChallenge *)challenge

    Parameters

    player

    The player who selected the challenge.

    challenge

    The challenge to be played by the player.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • Called when the player completes a challenge that was issued by a friend.

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, didCompleteChallenge challenge: GKChallenge!, issuedByFriend friendPlayer: GKPlayer!)

    Objective-C

    - (void)player:(GKPlayer *)player didCompleteChallenge:(GKChallenge *)challenge issuedByFriend:(GKPlayer *)friendPlayer

    Parameters

    player

    The player who completed the challenge.

    challenge

    The challenge the player completed.

    friendPlayer

    The friend who originally sent the challenge.

    Discussion

    This method is triggered when the game is running or when the user has tapped a challenge notification banner outside of the game.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • Called when a friend completes a challenge that was sent to them by the player.

    Declaration

    Swift

    optional func player(_ player: GKPlayer!, issuedChallengeWasCompleted challenge: GKChallenge!, byFriend friendPlayer: GKPlayer!)

    Objective-C

    - (void)player:(GKPlayer *)player issuedChallengeWasCompleted:(GKChallenge *)challenge byFriend:(GKPlayer *)friendPlayer

    Parameters

    player

    The player who originally sent the challenge.

    challenge

    The challenge that was created and sent.

    friendPlayer

    The player that completed the challenge.

    Discussion

    This method is triggered when the game is running or when the user has tapped a challenge notification banner outside of the game.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.10 and later.