What does GKSession not connect with every attempt?

The application invokes the DIDFail prompt, for some time it connects correctly, but sometimes it doesn’t ...

What could be the reasons for a connection failure?

// Display an alert sheet indicating a failure to connect to the peer. - (void) invitationDidFail:(SessionManager *)session fromPeer:(NSString *)participantID { NSString *str; if (alertView.visible) { // Peer cancelled invitation before it could be accepted/rejected // Close the invitation dialog before opening an error dialog [alertView dismissWithClickedButtonIndex:0 animated:NO]; [alertView release]; str = [NSString stringWithFormat:@"%@ is busy.\nPlease again", participantID]; //[peerList removeAllObjects]; [self peerListDidChange:nil]; [self.tableData reloadData]; //[self TwoPlayer:self]; } else { // Peer rejected invitation or exited app. str = [NSString stringWithFormat:@"%@ is busy.\nPlease try again", participantID]; //[peerList removeAllObjects]; [self peerListDidChange:nil]; [self.tableData reloadData]; //[self TwoPlayer:self]; } } 

Even he does not call this method. I am sure that the device is not paired with any other device, then for some reason it sometime accepts and calls the didReceivedInvitation method, or for some time when it refuses, having called the DidFail invitation.

 // Invitation dialog due to peer attempting to connect. - (void) didReceiveInvitation:(SessionManager *)session fromPeer:(NSString *)participantID; { [alertView dismissWithClickedButtonIndex:1 animated:NO]; NSString *str = [NSString stringWithFormat:@"Incoming Invite from %@", participantID]; if (alertView.visible) { [alertView dismissWithClickedButtonIndex:0 animated:NO]; [alertView release]; } alertView = [[UIAlertView alloc] initWithTitle:str message:@"Do you wish to accept?" delegate:self cancelButtonTitle:@"Decline" otherButtonTitles:nil]; [alertView addButtonWithTitle:@"Accept"]; [alertView show]; } 
0
source share
1 answer

When I recently wrote an application using connections, I used GKSession. I spent weeks trying to debug connection problems, and in the end I gave up and stopped using it. It seems that there are a number of problems with the GKSession when connecting, especially if you disconnected and then try to reconnect in a short time (a short time can be 1 minute or more). It looks like the connection is not being removed properly, and then the connection is not recreated correctly.

In the end, I pulled out all the GKSession code and used it instead. It worked with pleasure - more connection problems.

GCD Async Socket

+1
source

Source: https://habr.com/ru/post/1438980/


All Articles