Reputation: 11340
So, I'm writing a very simple real time game center 2-player game; however, the problem is I keep getting disconnected.
The game works as follows: Each player has a text field on their device. They each enter text in the field and press enter. When both people have inputted text, the game progresses.
Now, when the users are actively playing the game (inputting text every 10 seconds or so), the game works just fine and a user has never been disconnected. However, when the game remains inactive (the user just sits and stares at the app screen) for about 30 seconds or more, at least one player gets disconnected.
I'm pretty confident that my Internet is solid and both devices appear to be connected to the Internet (via wifi).
I know this is a very vague question, I was just wondering if anyone has any ideas related to the symptoms in bold above.
EDIT:
Here's how I initialize the matchrequest and the match. However, I'm having no trouble initializing or starting the match. The only problem is when a player goes idle for some length of time
//toInvite may be nil
- (void) createMatchWithPlayersToInvite: (NSArray *) toInvite
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = toInvite;
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
self.myMatchmakerVC = mmvc;
mmvc.hosted = NO;
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
[self dismissViewControllerAnimated:YES completion:nil];
self.myMatch = match;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.currentMatch = self.myMatch;
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
[self performSegueWithIdentifier:@"gameSegue" sender:self];
}
}
EDIT 2:
So, I've discovered that if I set a timer and send messages across the network (with [self.myMatch sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable error:&error]) every 1 second, the program works just fine. Does anyone have idea why this is or how I can fix my issue without resorting to a hacked together NSTimer
?
Other notes:
1) My AppDelegate
has not been changed
Upvotes: 2
Views: 1415
Reputation: 5664
Looks like you have a clear hypothesis here, i.e. that Game Center connections are closed after 30 seconds idle time. I would not be surprised if this is the case. Other games almost certainly will send data within such an interval, and you may be triggering a timeout condition. To test this hypothesis and fix the problem at the same time, I would send a short blind text every five or ten seconds.
Upvotes: 2