Problems with GKSession and sendDataToAllPeers:withDataMode:error: Problems with GKSession and sendDataToAllPeers:withDataMode:error: objective-c objective-c

Problems with GKSession and sendDataToAllPeers:withDataMode:error:


I think you are calling send to fast. When server realize about connection it will send confirmation to client to really establish connection - so client knows about it succeed.

If you are sending packets before that happens - it will be lost.

Just do this:

[self performSelector:@selector(sendPacketToAllClients) withObject:nil afterDelay:1.0];

instead of:

[self sendPacketToAllClients];

I had the same problem that connection is established in different moment with small delay on client. The best is to send first packet from client that he is ready to receive packets from server - and than proceed normally from there.

Also try debugging:

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state

On both devices (server and client).


I have also had my troubles with GKSession. I was interested to learn (on this site) today that GKSession is being deprecated in favor of using the Multipeer Connectivity Framework. With luck, Wenderlich et al. will do a tutorial using the new technology. :)

The system has some similarities to GKSession, so is not too hard to wrap your head around.

Apple's doc link.