Instance Method

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

Sends an exchange request to one or more participants.

Declaration

- (void)sendExchangeToParticipants:(NSArray<GKTurnBasedParticipant *> *)participants data:(NSData *)data localizableMessageKey:(NSString *)key arguments:(NSArray<NSString *> *)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. Listing 1 showws a basic exchange requeste.

Listing 1

Sending an exchange request to another player

- (void) exchangeRequest (GKTurnBasedParticipant receiver)
{
     NSArray *recipients = @[receiver];
     [self sendExchangeToParticipants:recipients data:data localizableMessageKey:key arguments:arguments timeout:timeout completionHandler:^(GKTurnBasedExchange *exchange, NSError *error) {
          // refresh your match data
     }];
}

See Also

Transferring Information with Exchanges

- saveMergedMatchData:withResolvedExchanges:completionHandler:

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

GKExchangeTimeoutDefault

The exchange will timeout after one day if no reply is received.

GKExchangeTimeoutNone

The exchange will not timeout.

activeExchanges

Returns the exchanges that are active for the local player.

completedExchanges

The exchanges that have been completed and need to be merged by the local participant.

exchangeDataMaximumSize

The maximum amount of data allowed for an exchange.

exchangeMaxInitiatedExchangesPerPlayer

Limits the number of exchanges the player can have initiated at once.

exchanges

The current exchanges that are in progress for the match.