views:

75

answers:

2

GKSession sendDataToAllPeers:withDataMode:error: is asynchronous ... or so I understand. Short of the peer sending an application-level ACK (which would be very clunky) is there a means of finding out when it's done sending?

M.

A: 

When you create your GKSession, set its dataReceiveHandler like so:

[self.gkSession setDataReceiveHandler:self withContext:nil];

The handler is a method with the following signature (in this case, this would be in the "self" object referenced above);

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;

This method is called when a peer receives data send through sendData:toPeers and sendDataToAllPeers:

Typeoneerror
A: 

When you do

[session sendDataToAllPeers:data withDataMode:GKSendDataReliable error:nil];

it will return "Yes" if the data was queued for transmission and "No" if it wasn't queued correctly. If you specified something for the "error" parameter, the issue will be saved there.

As far as confirming the message actually got to the recipient, I cannot find anything in the documentation (short of having the recipient send a message confirming receipt). If you use GKSendDataReliable as the mode it will keep attempting to send the message as many times as possible until the connection times out. Seems like your best option would be to to use a reliable mode, check if it was queued correctly, and if you need to react once the message got received, send a confirmation.

Pablo