GKChallenge Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/GameKit.framework
Availability
Available in OS X v10.9 and later.
Companion guide
Declared in
GKChallenge.h

Overview

A GKChallenge object represents a challenge issued by a player to another player.

Players use the Game Center app to issue and view challenges. However, your game can also customize its challenge behaviors in a number of ways:

Subclassing Notes

You never subclass the GKChallenge class directly. However, subclasses of GKChallenge represent specific kinds of challenges. Two challenge types exist:

Tasks

Retrieving the List of Challenges to the Local Player

Examining Details About a Challenge

Declining a Challenge

Properties

completionDate

The date the challenge was completed. (read-only)

@property(nonatomic, readonly, retain) NSDate *completionDate
Discussion

If the challenge is not complete, this value is nil.

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

issueDate

The date the challenge was issued. (read-only)

@property(nonatomic, readonly, retain) NSDate *issueDate
Availability
  • Available in OS X v10.8 and later.
Declared In
GKChallenge.h

issuingPlayerID

The player identifier for the player who issued the challenge. (read-only)

@property(nonatomic, readonly, copy) NSString *issuingPlayerID
Availability
  • Available in OS X v10.8 and later.
Declared In
GKChallenge.h

message

A text message that describes the challenge. (read-only)

@property(nonatomic, readonly, copy) NSString *message
Availability
  • Available in OS X v10.8 and later.
Declared In
GKChallenge.h

receivingPlayerID

The player identifier for the player who received the challenge. (read-only)

@property(nonatomic, readonly, copy) NSString *receivingPlayerID
Availability
  • Available in OS X v10.8 and later.
Declared In
GKChallenge.h

state

The current state of the challenge. (read-only)

@property(nonatomic, readonly, assign) GKChallengeState state
Discussion

See “Challenge State” for possible values.

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

Class Methods

loadReceivedChallengesWithCompletionHandler:

Loads the list of outstanding challenges.

+ (void)loadReceivedChallengesWithCompletionHandler:(void (^)(NSArray *challenges, NSError *error))completionHandler
Parameters
completionHandler

A block to be called when the download is completed.

The block receives the following parameters:

challenges

An array of GKChallenge objects that represents all challenges made to the local player. If an error occurred, this parameter may be non-nil, in which case the array holds whatever challenge information Game Kit was able to fetch.

error

If an error occurred, this object describes the error. If the operation completed successfully, this value is nil.

Discussion

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread.

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

Instance Methods

decline

Declines a challenge.

- (void)decline
Discussion

If your game implements a custom user interface to display challenges, it should include controls that allow a player to decline a challenge. If the player uses your user interface to decline a challenge, call this method.

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

Constants

Challenge State

Possible states that a challenge can live in.

typedef enum GKChallengeState {     GKChallengeStateInvalid = 0,
   GKChallengeStatePending = 1,
   GKChallengeStateCompleted = 2,
   GKChallengeStateDeclined = 3,
};
Constants
GKChallengeStateInvalid

An error occurred. The state of this challenge is not valid.

Available in OS X v10.8 and later.

Declared in GKChallenge.h.

GKChallengeStatePending

The challenge has been issued, but is not yet completed nor declined.

Available in OS X v10.8 and later.

Declared in GKChallenge.h.

GKChallengeStateCompleted

The receiving player successfully completed the challenge.

Available in OS X v10.8 and later.

Declared in GKChallenge.h.

GKChallengeStateDeclined

The receiving player declined the challenge.

Available in OS X v10.8 and later.

Declared in GKChallenge.h.