Contents

GKTurnBasedExchange

Exchange request information that participants send in a turn-based match.

Declaration

class GKTurnBasedExchange

Mentioned in

Overview

GameKit sends exchange objects to GKTurnBasedEventListener protocol methods when the local player receives an exchange request or recipients reply to an exchange request. The exchange object encapsulates your custom game data that you want to communicate to other players.

You initiate an exchange request using the GKTurnBasedMatch sendExchange(to:data:localizableMessageKey:arguments:timeout:completionHandler:) method. Then GameKit sends the request to the recipients passing the exchange object to the GKTurnBasedEventListener player(_:receivedExchangeRequest:for:) protocol method. GameKit sets the status of the exchange object to GKTurnBasedExchangeStatus.active.

After all recipients respond to the request, using the reply(withLocalizableMessageKey:arguments:data:completionHandler:) method, or exceed the time out specified in the request, GameKit sends the exchange to the sender and the current participant. GameKit sets the exchange status to GKTurnBasedExchangeStatus.complete and then passes it to the GKTurnBasedEventListener player(_:receivedExchangeReplies:forCompletedExchange:for:) method.

Before the current participant ends their turn, save the completed exchanges using the GKTurnBasedMatch saveMergedMatch(_:withResolvedExchanges:completionHandler:) method. Get the exchanges from the match object using the completedExchanges property. Alternatively, save exchange data in the player(_:receivedExchangeReplies:forCompletedExchange:for:) protocol method when all recipients reply to specific exchange requests.

To cancel an active or complete exchange, use the cancel(withLocalizableMessageKey:arguments:completionHandler:) method. GameKit notifies the recipients when the player cancels an exchange, using the GKTurnBasedEventListener player(_:receivedExchangeCancellation:for:) protocol method.

Topics

Retrieving Exchange Details

Replying to Exchange Requests

Canceling Exchange Requests

See Also

Turn-based games