GKTurnBasedMatch Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/GameKit.framework
Availability
Available in iOS 5.0 and later.
Companion guide
Declared in
GKTurnBasedMatch.h

Overview

The GKTurnBasedMatch class allows your game to implement turn-based matches between sets of players on Game Center. A turn-based match uses a store-and-forward approach to share data between the participants. When a player participating in the match performs actions that advance the state of the match, your game describes the new state of the match and decides which player acts next. The next player to act is notified by a push notification. Later, when the next player launches your game, you download the match data from Game Center and continue the match. Players take turns acting (based on whatever internal logic your game implements) until the match ends. One advantage of turn-based matches is that a player may participate in multiple matches simultaneously.

Your game never directly creates GKTurnBasedMatch objects, because a match always represents an existing match that is stored by Game Center. Instead, match objects are created for your game by Game Kit. A match object may hold a newly created match (for a match that has not started yet) or a match that is already under way. Here are ways your game acquires match objects:

A match object contains a few essential properties:

When a player views a particular match, your game should take the match object and call its loadMatchDataWithCompletionHandler: method to retrieve the match data. After the match data is downloaded from Game Center, your game parses the data and displays the game’s user interface. A player may want to view the match even when it is another player’s turn to act; your game should expect this and allow the player to view the state of the match without allowing them to act. When the current player views the match, your game should both show them the state of the match and provide a user interface to allow the player to take a turn. The current player is expected to perform actions that change the state of the match. These actions are based on the internal logic of your game’s rules. The player continues to act until he or she takes an action that requires another person in the match to act in order to advance the match. For example, in a game like Chess, moving a piece on the board and passing control to the other participant happen simultaneously. A more complex game might allow the current player to take multiple actions before the match reaches a state in which control is ceded to another player.

If the player takes an action that is irrevocable (but control is not yet passed to another player), you update the match data by calling the saveCurrentTurnWithMatchData:completionHandler: method.

Once the player takes an action that requires another player to act, your game should determine which player needs to act next. Then, it should encode the state of the match into an NSData object and call the match object’s endTurnWithNextParticipants:turnTimeout:matchData:completionHandler: method to set the next player to act. The next player is automatically informed that the match is waiting on his or her actions in order to continue the match.

As the match progresses, players may leave the match. For example, this situation might occur if your game determines that this player has been eliminated from the match. Or your game might offer a user interface to allow players to resign from matches. If the local player resigns from the match and is also the match’s current player, your game must call the match object’s participantQuitInTurnWithOutcome:nextParticipant:matchData:completionHandler: method. As it does when the player takes a turn, your game passes in the state of the match and the next player to act. Your game also provides a match outcome — essentially, a numerical value that indicates the reason why that player left the match. If your game allows players to resign from matches when it is not that player’s turn, your game calls the match object’s participantQuitOutOfTurnWithOutcome:withCompletionHandler: method to allow the player to leave the match.

Eventually, a match ends. When your game logic dictates that a match should end, your game calls the match object’s endMatchInTurnWithMatchData:completionHandler: method. Your game must ensure that all participants in the match have a valid match outcome before ending the match.

Even after a match ends, its data is still stored on Game Center; this allows players to view previous victories and defeats. A player may choose to delete the match using the standard user interface, but your game can also programmatically remove a match by calling the match object’s removeWithCompletionHandler: method. In all cases, the decision to delete a match should be made by a player; the removeWithCompletionHandler: method exists to allow your game to present a custom user interface for viewing and working with matches.

Subclassing Notes

The GKTurnBasedMatch class may not be subclassed.

Tasks

Retrieving Existing Matches

Creating a New Match

Retrieving Information About the Match

Retrieving the Match’s Custom Data

Handling the Current Player’s Turn

Leaving a Match

Ending a Match

Deleting a Match From Game Center

Transferring Information with Exchanges

Sending Messages Between Players

Properties

activeExchanges

Returns the exchanges that are active for the local player. (read-only)

@property(readonly, retain, nonatomic) NSArray *activeExchanges
Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

completedExchanges

The exchanges that have been completed and need to be merged by the local participant. (read-only)

@property(readonly, retain, nonatomic) NSArray *completedExchanges
Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

creationDate

The date that the match was created. (read-only)

@property(readonly, retain, nonatomic) NSDate *creationDate
Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

currentParticipant

The participant whose turn it is to act next. (read-only)

@property(readonly, retain, nonatomic) GKTurnBasedParticipant *currentParticipant
Discussion

The current participant is the only participant that is allowed to update the match data.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

exchangeDataMaximumSize

The maximum amount of data allowed for an exchange. (read-only)

@property(readonly, nonatomic) NSUInteger exchangeDataMaximumSize
Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

exchangeMaxInitiatedExchangesPerPlayer

Limits the number of exchanges the player can have initiated at once. (read-only)

@property(readonly, nonatomic) NSUInteger exchangeMaxInitiatedExchangesPerPlayer
Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

exchanges

The current exchanges that are in progress for the match. (read-only)

@property(readonly, retain, nonatomic) NSArray *exchanges
Discussion

When an exchanges has been completed and resolved by merging it into the match data, it will be removed from this list.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

matchData

Game-specific data that reflects the details of the match. (read-only)

@property(readonly, retain, nonatomic) NSData *matchData
Discussion

Although Game Center knows who is participating in the match and who is expected to act next, it does not know anything about your game’s internal logic. Your game provides the match data and all the programming logic required to interpret it. This data should include the current state of the game and provide any necessary details about what actions the current player is expected to take. It can also be helpful for your game to record information about recent moves made by other players. The game can then replay those moves visually for the player to show exactly how the match reached the state it is in now.

Your game never directly updates the match state associated with this property. Instead, when the data is updated to reflect the actions of the current player, your game serializes the updated state into memory and calls one of the match’s instance methods that transmit the updated state to Game Center.

The value of this property is nil until after your game calls the loadMatchDataWithCompletionHandler: method and the load task is complete. After this task completes, the matchData property holds the data that the last player to act transmitted to Game Center.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

matchDataMaximumSize

Returns the limit the Game Center servers place on the size of the match data. (read-only)

@property(readonly, nonatomic) NSUInteger matchDataMaximumSize
Discussion

Game Kit returns an error if your game sends updated data larger than this value.

Availability
  • Available in iOS 6.0 and later.
Declared In
GKTurnBasedMatch.h

matchID

A string that uniquely identifies the match. (read-only)

@property(readonly, retain, nonatomic) NSString *matchID
Discussion

This string is not intended to be displayed to players. Your game should use this string whenever it needs to identify a specific match. For example, if you want your game to store additional information on a device or in iCloud, it might store it in a database using the match ID as a key.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

message

A message displayed to all players in the match.

@property(readwrite, copy, nonatomic) NSString *message
Discussion

The message property is displayed by the standard user interface; this allows your game to use the message to inform players of the current state of the match.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

participants

Information about the players participating in the match. (read-only)

@property(readonly, retain, nonatomic) NSArray *participants
Discussion

The elements of this array are GKTurnBasedParticipant objects representing each participant in the match. Your game uses these objects to retrieve more information about the participants in the match. Your game also uses one of the objects in this array as a parameter whenever it calls a method that sets a different participant to act in the match.

The size of the array and the order in which the participants appear in the array are set when the match is first created, and never changes. When a match is first created, some participants may not hold actual players yet. Game Center searches for a player to fill that spot in the match only after your game sets that participant as the current player.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

status

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

@property(readonly, nonatomic) GKTurnBasedMatchStatus status
Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

Class Methods

findMatchForRequest:withCompletionHandler:

Programmatically searches for a new match to join.

+ (void)findMatchForRequest:(GKMatchRequest *)request withCompletionHandler:(void (^)(GKTurnBasedMatch *match, NSError *error))completionHandler
Parameters
request

A match request that specifies the properties that the new match must fulfill.

completionHandler

A block to be called after the match is successfully created.

The block receives the following parameters:

match

A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

error

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

Discussion

When this method is called, it creates a 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.

This method may either create a new match or it may place the player into an existing match that needs a new player to advance the match further. Regardless of how the player is placed in the match, the local player is always the current participant in the returned match. Your game should immediately display the match in its user interface and allow the player to take a turn.

To be consistent with older servers and versions of iOS, the minimum number of players specified by the GKMatchRequest object is set to be equal to the maximum number of players when looking for a match.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

loadMatchesWithCompletionHandler:

Loads the turn-based matches involving the local player and creates a match object for each match.

+ (void)loadMatchesWithCompletionHandler:(void (^)(NSArray *matches, NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the matches are retrieved from the server.

The block receives the following parameters:

matches

An array of GKTurnBased Match objects containing the match objects for matches that the local player is playing in, or nil if there are no matches to load. If an error occurred, this value may be non-nil. In this case, the array holds whatever match data could be retrieved from Game Center before the error occurred.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

loadMatchWithID:withCompletionHandler:

Loads a specific match.

+ (void)loadMatchWithID:(NSString *)matchID withCompletionHandler:(void (^)(GKTurnBasedMatch *match, NSError *error))completionHandler
Parameters
matchID

The identifier for the turn-based match.

completionHandler

A block to be called after the match is retrieved from the server.

The block receives the following parameters:

match

If the operation completed successfully, this parameter holds the match. If an error occurred, the value is nil.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

Instance Methods

acceptInviteWithCompletionHandler:

Programmatically accept an invitation to a turn-based match.

- (void)acceptInviteWithCompletionHandler:(void (^)(GKTurnBasedMatch *match, NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the match is successfully created.

The block receives the following parameters:

match

A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

declineInviteWithCompletionHandler:

Programmatically decline an invitation to a turn-based match.

- (void)declineInviteWithCompletionHandler:(void (^)(NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the match is successfully created.

The block receives the following parameter:

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

endMatchInTurnWithMatchData:completionHandler:

Ends the match.

- (void)endMatchInTurnWithMatchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchData

A serialized blob of data reflecting the end state for the match. Do not pass nil as an argument.

completionHandler

A block to be called after the match is successfully ended.

The block receives the following parameters:

error

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

Discussion

Calling this method ends the match for all players. This method may only be called by the current participant. Before your game calls this method, the matchOutcome property on each participant object stored in the participants property must have been set to a value other than GKTurnBasedMatchOutcomeNone.

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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

endMatchInTurnWithMatchData:scores:achievements:completionHandler:

Ends the match while submitting all of the scores and achievements.

- (void)endMatchInTurnWithMatchData:(NSData *)matchData scores:(NSArray *)scores achievements:(NSArray *)achievements completionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchData

A serialized blob of data reflecting the current state for the match. Do not pass nil as an argument.

scores

An array of GKScore objects containing the final scores for every participant in the match.

achievements

An array of GKAchievement objects containing the achievements acquired by each participant in the match.

completionHandler

A block to be called after the scores are saved to the server.

The block receives the following parameters:

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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.

This method ends the current match and submits scores and achievements for all of the participants. The scores can submitted to multiple leaderboards. The GKTurnBasedMatchOutcome status must be set for each participant before calling this method.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

endTurnWithNextParticipants:turnTimeout:matchData:completionHandler:

Updates the data stored on Game Center for the current match.

- (void)endTurnWithNextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler
Parameters
nextParticipants

An array of GKTurnBasedParticipant objects reflecting the order in which the players should act next. Each object in the array must be one of the objects stored in the match’s participants property.

timeout

The length of time the next player has to complete their turn.

matchData

A serialized blob of data reflecting the game-specific state for the match. Do not pass nil as an argument.

completionHandler

A block to be called after the data is uploaded to Game Center.

The block receives the following parameters:

error

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

Discussion

If the next player to act does not take their turn in the specified interval, the next player in the array receives a notification to act. This process continues until a player takes a turn or the last player in the list is notified.

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 iOS 6.0 and later.
Declared In
GKTurnBasedMatch.h

loadMatchDataWithCompletionHandler:

Loads the game-specific data associated with a match, including all exchanges.

- (void)loadMatchDataWithCompletionHandler:(void (^)(NSData *matchData, NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the match data is retrieved from the server.

The block receives the following parameters:

matchData

The data stored on Game Center that reflects the current state of the match. If an error occurred, this value is nil.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

participantQuitInTurnWithOutcome:nextParticipants:turnTimeout:matchData:completionHandler:

Resigns the current player from the match without ending the match.

- (void)participantQuitInTurnWithOutcome:(GKTurnBasedMatchOutcome)matchOutcome nextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchOutcome

The end outcome of the current player in the match. Do not pass nil as an argument.

nextParticipants

An array of GKTurnBasedParticipant objects that contains participant objects reflecting the order in which the players should act next. Each object in the array must be one of the objects stored in the match’s participants property.

timeout

The length of time the next player has to complete their turn.

matchData

A serialized blob of data reflecting the game-specific state for the match.

completionHandler

A block to be called after the data is uploaded to the server.

The block receives the following parameters:

error

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

Discussion

Your game calls this method on an instance of your game that is processing the current player’s turn, but that player has left the match. For example, the player may have willingly resigned from the match or that player may have been eliminated by the other players (based on your game’s internal logic).

If the next player to act does not take their turn in the specified interval, the next player in the array receives a notification to act. This process continues until a player takes a turn or the last player in the list is notified.

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 iOS 6.0 and later.
Declared In
GKTurnBasedMatch.h

participantQuitOutOfTurnWithOutcome:withCompletionHandler:

Resigns the player from the match when that player is not the current player. This action does not end the match

- (void)participantQuitOutOfTurnWithOutcome:(GKTurnBasedMatchOutcome)matchOutcome withCompletionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchOutcome

The end outcome of the current player in the match. Do not pass nil as an argument.

completionHandler

A block to be called after the player’s status is updated on Game Center.

The block receives the following parameters:

error

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

Discussion

If the local player decided they wanted to resign from the match but is not the current participant in the match, your game calls this method.

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 iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

rematchWithCompletionHandler:

Create a new turn-based match with the same participants as an existing match.

- (void)rematchWithCompletionHandler:(void (^)(GKTurnBasedMatch *match, NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the match is successfully created.

The block receives the following parameters:

match

A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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 iOS 6.0 and later.
Declared In
GKTurnBasedMatch.h

removeWithCompletionHandler:

Programmatically removes a match from Game Center.

- (void)removeWithCompletionHandler:(void (^)(NSError *error))completionHandler
Parameters
completionHandler

A block to be called after the match has been removed from Game Center.

The block receives the following parameters:

error

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

Discussion

Even after a player’s participation in a match ends, the data associated with the match continues to be stored on Game Center. Storing the data on Game Center allows the player to continue to watch the match’s progress, or even see the final state of the match when it ends. However, players may also want to delete matches that they have finished playing. If you choose not to use the standard matchmaker user interface, your game should offer the ability to delete a finished match from Game Center. When a player chooses to delete a match from Game Center, call this method. It is a programming error to call this method on a match that has the local player as an active participant.

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.

When the task completes, the match is no longer visible to the local player whose device made the call. Other players involved in the match still see the match.

Availability
  • Available in iOS 5.0 and later.
Declared In
GKTurnBasedMatch.h

saveCurrentTurnWithMatchData:completionHandler:

Update the match data without advancing the game to another player.

- (void)saveCurrentTurnWithMatchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchData

A serialized blob of data reflecting the game-specific state for the match. Do not pass nil as an argument.

completionHandler

A block to be called after the data is uploaded to Game Center.

The block receives the following parameters:

error

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

Discussion

This method updates the match data stored on Game Center. Call this method when the current player takes an action that advances the state of the match but does not end the player’s turn. For example, if your game has a fog-of-war mechanic, you might call this method when the player revealed new information on the map.

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 iOS 6.0 and later.
Declared In
GKTurnBasedMatch.h

saveMergedMatchData:withResolvedExchanges:completionHandler:

Saves the merged data for the current turn without ending the turn.

- (void)saveMergedMatchData:(NSData *)matchData withResolvedExchanges:(NSArray *)exchanges completionHandler:(void (^)(NSError *error))completionHandler
Parameters
matchData

A serialized blob of data reflecting the current state for the match.

exchanges

An array of GKTurnBasedExchange objects that contains the resolved exchanges.

completionHandler

A block to be called after the scores are saved to the server.

The block receives the following parameters:

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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.

When this method is called, the data sent is marked as being resolved. This means that the data has been merged into the match data. If other players currently have the game running, they will receive a handleTurnEventForMatch call to indicate that matchData has changed. All completed exchanges must be resolved before ending a turn. If the completed exchanges have not been resolved, then calling endTurn, participantQuitInTurnWithOutCome, or endMatchInTurn will result in an error.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

sendExchangeToParticipants:data:localizableMessageKey:arguments:timeout:completionHandler:

Sends an exchange request to one or more participants.

- (void)sendExchangeToParticipants:(NSArray *)participants data:(NSData *)data localizableMessageKey:(NSString *)key arguments:(NSArray *)arguments timeout:(NSTimeInterval)timeout completionHandler:(void (^)(GKTurnBasedExchange *exchange, NSError *error))completionHandler
Parameters
participants

An array of GKTurnBasedParticipant objects containing the participants who are to receive the reminder.

data

The data to be exchanged between players.

key

The location of the alert message string in the Localizable.strings file for the current localization.

arguments

An array of NSString objects to be substituted using the format string.

timeout

The length of time the next player has to complete their turn.

completionHandler

A block to be called after the exchange request has been sent.

The block receives the following parameters:

exchange

The updated exchange to be passed.

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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.

Allows an exchange request to be sent to one or more participants. Each recipient receives a push notification that uses the supplied localizable message. An error is returned if any of the participants are inactive.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

sendReminderToParticipants:localizableMessageKey:arguments:completionHandler:

Send a reminder to one or more game participants.

- (void)sendReminderToParticipants:(NSArray *)participants localizableMessageKey:(NSString *)key arguments:(NSArray *)arguments completionHandler:(void (^)(NSError *error))completionHandler
Parameters
participants

An array of GKTurnBasedParticipant objects containing the participants who are to receive the reminder.

key

The location of the alert message string in the Localizable.strings file for the current localization.

arguments

An array of objects to be substituted using the format string.

completionHandler

A block to be called after the reminder has been sent.

The block receives the following parameters:

error

If an error occurred, this error object describes the error. If the operation was completed successfully, the 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.

When this method is called, each recipient receives a push notification using the supplied localizable message. This allows the game to send reminders that a turn or exchange request needs action. The receiver will have a turn event generated for the current game.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

setLocalizableMessageWithKey:arguments:

Allows the developer to display a message at the end of a turn or match.

- (void)setLocalizableMessageWithKey:(NSString *)key arguments:(NSArray *)arguments
Parameters
key

The location of the alert message string in the Localizable.strings file for the current localization.

arguments

An array of NSString objects to be substituted using the format string.

Discussion

Only the current player is able to set this message. The message sent is localized on the receiver side if the game is installed and on the sender side otherwise. The localized message identified through the key parameter can be formatted with the %@ and %n$@ specifiers. These specifiers use the objects designated in the arguments array.

The localized message is evaluated locally from these keys and is sent as well so that devices that do not have the game installed will see the message in the sender’s localization.

Availability
  • Available in iOS 7.0 and later.
Declared In
GKTurnBasedMatch.h

Constants

GKTurnBasedMatchStatus

The different states that a match can enter.

enum {
   GKTurnBasedMatchStatusUnknown = 0,
   GKTurnBasedMatchStatusOpen = 1,
   GKTurnBasedMatchStatusEnded = 2,
   GKTurnBasedMatchStatusMatching = 3
};
typedef NSInteger GKTurnBasedMatchStatus;
Constants
GKTurnBasedMatchStatusUnknown

The match is in an unexpected state.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchStatusOpen

The match is currently being played.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchStatusEnded

The match has been completed.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchStatusMatching

Game Center is still searching for other players to join the match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatus

The different states for a particular participant in a match.

enum {
   GKTurnBasedParticipantStatusUnknown = 0,
   GKTurnBasedParticipantStatusInvited = 1,
   GKTurnBasedParticipantStatusDeclined = 2,
   GKTurnBasedParticipantStatusMatching = 3,
   GKTurnBasedParticipantStatusActive = 4,
   GKTurnBasedParticipantStatusDone = 5,
};
typdef NSInteger GKTurnBasedParticipantStatus;
Constants
GKTurnBasedParticipantStatusUnknown

The current state of the participant is not known.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatusInvited

The participant has been invited to a match, but has not yet responded to the invite.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatusDeclined

The participant has declined a match invitation.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatusMatching

The participant is waiting to be matched to a game.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatusActive

The participant is currently active in the match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedParticipantStatusDone

The participant is done with the current session.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcome

Descriptions for the different game result states for a given participant that has reached the done state.

enum {
   GKTurnBasedMatchOutcomeNone = 0,
   GKTurnBasedMatchOutcomeQuit = 1,
   GKTurnBasedMatchOutcomeWon = 2,
   GKTurnBasedMatchOutcomeLost = 3,
   GKTurnBasedMatchOutcomeTied = 4,
   GKTurnBasedMatchOutcomeTimeExpired = 5,
   GKTurnBasedMatchOutcomeFirst = 6,
   GKTurnBasedMatchOutcomeSecond = 7,
   GKTurnBasedMatchOutcomeThird = 8,
   GKTurnBasedMatchOutcomeFourth = 9,
   GKTurnBasedMatchOutcomeCustomRange = 0x00FF0000
};
typedef NSInteger GKTurnBasedMatchOutcome;
Constants
GKTurnBasedMatchOutcomeNone

The participant has not finished a match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeQuit

Participant quit the match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeWon

Participant won the match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeLost

Participant lost the match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeTied

Participant tied in the current match.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeTimeExpired

The game ended due to time running out.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeFirst

The participant came in first.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeSecond

The participant came in second.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeThird

The participant came in third.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeFourth

The participant came in fourth.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnBasedMatchOutcomeCustomRange

Custom range available for an app to use for its own status results.

Available in iOS 5.0 and later.

Declared in GKTurnBasedMatch.h.

Turn Timeouts

Common values for turn timeouts.

extern NSTimeInterval GKTurnTimeoutDefault;
extern NSTimeInterval GKTurnTimeoutNone;
Constants
GKTurnTimeoutDefault

Indicates that the player has one week to take a turn.

Available in iOS 6.0 and later.

Declared in GKTurnBasedMatch.h.

GKTurnTimeoutNone

Indicates that the player’s turn never times out.

Available in iOS 6.0 and later.

Declared in GKTurnBasedMatch.h.