GKChallenge Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/GameKit.framework |
| Availability | Available in iOS 6.0 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:
You can load the list of challenges issued to the local player by calling the
loadReceivedChallengesWithCompletionHandler:class method. For example, you might do this to display the challenges in your game’s user interface.Your app can issue challenges using a
GKScoreorGKAchievementobject. Your game should only issue challenges when the local player initiates the action in your user interface.Your game can be notified when new challenge events are received. See
GKChallengeEventHandlerDelegate.
Subclassing Notes
You never subclass the GKChallenge class directly. However, subclasses of GKChallenge represent specific kinds of challenges. Two challenge types exist:
A
GKScoreChallengeis a challenge to beat a score the local player earned in a leaderboard.A
GKAchievementChallengeis a challenge to complete an achievement that the local player has already completed.
Tasks
Retrieving the List of Challenges to the Local Player
Examining Details About a Challenge
-
issueDateproperty -
issuingPlayerIDproperty -
receivingPlayerIDproperty -
messageproperty -
stateproperty -
completionDateproperty
Declining a Challenge
Properties
completionDate
The date the challenge was completed. (read-only)
Discussion
If the challenge is not complete, this value is nil.
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hissueDate
The date the challenge was issued. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hissuingPlayerID
The player identifier for the player who issued the challenge. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hmessage
A text message that describes the challenge. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hreceivingPlayerID
The player identifier for the player who received the challenge. (read-only)
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hstate
The current state of the challenge. (read-only)
Discussion
See “Challenge State” for possible values.
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hClass Methods
loadReceivedChallengesWithCompletionHandler:
Loads the list of outstanding challenges.
Parameters
- completionHandler
A block to be called when the download is completed.
The block receives the following parameters:
- challenges
An array of challenge 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. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.
Availability
- Available in iOS 6.0 and later.
Declared In
GKChallenge.hInstance Methods
decline
Declines a challenge.
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 iOS 6.0 and later.
Declared In
GKChallenge.hConstants
Challenge State
Possible states that a challenge can live in.
typedef enum GKChallengeState { GKChallengeStateInvalid = 0,
GKChallengeStatePending = 1,
GKChallengeStateCompleted = 2,
GKChallengeStateDeclined = 3,
};
Constants
GKChallengeStateInvalidAn error occurred. The state of this challenge is not valid.
Available in iOS 6.0 and later.
Declared in
GKChallenge.h.GKChallengeStatePendingThe challenge has been issued, but is not yet completed nor declined.
Available in iOS 6.0 and later.
Declared in
GKChallenge.h.GKChallengeStateCompletedThe receiving player successfully completed the challenge.
Available in iOS 6.0 and later.
Declared in
GKChallenge.h.GKChallengeStateDeclinedThe receiving player declined the challenge.
Available in iOS 6.0 and later.
Declared in
GKChallenge.h.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)