I have a GKSession between two apps. One is the server, the other the client. The server causes the client app to launch another app with a urlscheme command.
What I WISH would happen is that when the client app shuts down, the session ends, the other app opens up, and we start a new session.
What is actually happening is a bit of a mystery to me. Basically, the new app opens up and begins communicating with the server. A good number of packets are sent back and forth between the two... but after a short period of time (3-5 seconds), the GKPeerStateDisconnected case happens in the session:peer:didChangeState: with the previous app that was connected. This stops all communication between the applications.
I was originally using the peer picker for this and it worked just fine (except there were lots of manual button pressing you needed to do). Now I need to remove the peer picker and have this process happen automatically.
-(void)session:(GKSession *)session
peer:(NSString *)peerID
didChangeState:(GKPeerConnectionState)state
{
BOOL peerChanged = NO;
NSLog(@"peer:%@ didChangeState: %d", peerID, state);
switch(state) {
case GKPeerStateAvailable:
[session connectToPeer:peerID withTimeout:1000];
peerChanged = YES;
break;
case GKPeerStateUnavailable:
peerChanged = YES;
break;
case GKPeerStateConnected:
[self.peerList addObject:peerID];
[self setupConnectionWithPeer:peerID toSession:session];
break;
case GKPeerStateDisconnected:
[self.peerList removeObject:peerID];
if(self.peerList.count == 0) self.isConnected = NO;
break;
}
NSLog(@"Number of peers: %d", self.peerList.count);
}