Game Center Matchmaking GKTurnBasedMatch有明显的滞后(〜1分钟)

我正在通过gamecenter实现一个多人模式的回合制游戏。 我有2个设备(1 ipad,1个iphone)在沙箱模式下testing,工作正常,但最近它已经开始在自动配对过程中挣扎。 在我从一个用户发送第一个转向后,另一个设备不会立即识别该游戏,而是开启自己的新游戏。 在能够立即发现在其他设备上启动的游戏之前,配对相当简单。 我不记得改变任何有关配对的部分( NSCodingGKTurnBasedEventHandlerGKTurnBasedMatchmakerViewControllerDelegate委托方法等)。

现在我从一台设备发送第一个回合,需要等待大约1分钟,以便其他设备可以成功连接到该游戏。 连接发生后,endTurnWithMatchData调用没有任何问题,它可以在1-2秒内发送和接收数据。 但是如果用户开始一个新鲜的游戏,并且不得不等待1分钟,那么另一个用户就可以连接到他的游戏。 有没有人在汽车配对过程中遇到明显的滞后? 我还没有实施邀请,所以我无法检查。 我用NSKeyedArchiver存档的比赛数据看起来相当大,3396字节,甚至对于几乎没有数据的新游戏。 这里是我的代码的相关部分:

GameOptionsViewController

 - (void)turnBasedMatchmakerViewControllerWasCancelled:(GKTurnBasedMatchmakerViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFailWithError:(NSError *)error { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match { [self dismissViewControllerAnimated:NO completion:nil]; self.gcMatch = match; [self performSegueWithIdentifier:@"GameMultiplayer" sender:self]; } - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"GameMultiplayer"]) { GameViewController *GameVC = (GameViewController *)segue.destinationViewController; [GameVC setGameMode:GAMEMODE_MULTIPLAYER_SAMEDEVICE]; //Multiplayer game it is if(self.gcMatch != nil) { [GameVC setGameMode:GAMEMODE_MULTIPLAYER_GAMECENTER]; GameVC.gcMatchDelegate = self; GameVC.gcMatch = self.gcMatch; NSLog(@"Game OVC Segue: Match ID | %@", self.gcMatch.matchID); } } else { ... } } 

GameViewController

 //This method is called according to user actions //It's the only method I use to send data to other participant -(void) sendCurrentGameDataWithNewTurn:(BOOL) newTurn { NSLog(@"Sending game data current participant : %@", gcMatch.currentParticipant.playerID); //Update match data if it is corrupted anyhow if (gcMatch.currentParticipant == nil) { [GKTurnBasedMatch loadMatchWithID:gcMatch.matchID withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) { if (error != nil) { NSLog(@"Error :%@", error); return ; } [self sendCurrentGameDataWithNewTurn:newTurn]; }]; } else { NSData *matchData = [NSKeyedArchiver archivedDataWithRootObject:game]; //Game advances to new player, buttons are disabled if(newTurn) { NSLog(@"SENDING NEW TURN"); NSUInteger currentIndex = [gcMatch.participants indexOfObject:gcMatch.currentParticipant]; GKTurnBasedParticipant *nextParticipant; nextParticipant = [gcMatch.participants objectAtIndex: ((currentIndex + 1) % [gcMatch.participants count])]; [gcMatch endTurnWithNextParticipants:[NSArray arrayWithObject:nextParticipant] turnTimeout:GC_TURN_TIMEOUT matchData:matchData completionHandler:^(NSError *error) { NSLog(@"Sent"); if (error) { NSLog(@"SNT - %@", error); } }]; } else { NSLog(@"ONLY UPDATING DATA"); [gcMatch saveCurrentTurnWithMatchData:matchData completionHandler:^(NSError *error) { NSLog(@"Sent"); if (error) { NSLog(@"OUD - %@", error); } }]; } } 

}

 -(void) updateGameDataWithGCMatch { //Update whole game data self.game = [NSKeyedUnarchiver unarchiveObjectWithData:self.gcMatch.matchData]; //Update game ui ... } -(void) handleTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive { //Check if I got data for the currently active match that options vc forwarded me here, if not do some debug print and return if(![self.gcMatch.matchID isEqual:match.matchID]) { //For debugging reasons I skip if i get info for any previous match (other player quit etc) NSLog(@"GCMatch matchID: %@ match matchID: %@",self.gcMatch.matchID,match.matchID); return; } NSLog(@"Turn event handle"); self.gcMatch = match; if([match.currentParticipant.playerID isEqualToString: [GKLocalPlayer localPlayer].playerID ]) { //Disable field buttons [self setFieldButtonsEnabled:TRUE]; [self turnChangeAnimationFromLeftToRight:FALSE]; } [self updateGameDataWithGCMatch]; } 

至于你的问题:

我自己在比赛中心进行了很多比赛,经常比较落后,这已经被certificate不是由我的网站造成的,而是由苹果游戏中心的服务器造成的。

至于额外的指导:

据我所见,你目前在设备上进行配对的方法是:

看看是否有匹配我可以连接 – >如果是请求gamedata和连接到匹配ELSE开始你自己的比赛和播放matchdata

根据我的经验,最好从matchrequestbroadcasts开始,等到find第二个玩家,定义服务器设备(例如,通过较低的游戏中心名称校验和),然后在该设备上启动游戏。