Game center GKMatch委托函数didStateChange调用两次或延迟调用
我正在做一个多人游戏,我的比赛成功开始了。我有三个球员在我的情况下。玩家1,玩家2,玩家3。 在Player3中,我调用了GKMatch对象的disconnect方法,我的disconnect方法是Game center GKMatch委托函数didStateChange调用两次或延迟调用,game-center,gkmatchmaker,Game Center,Gkmatchmaker,我正在做一个多人游戏,我的比赛成功开始了。我有三个球员在我的情况下。玩家1,玩家2,玩家3。 在Player3中,我调用了GKMatch对象的disconnect方法,我的disconnect方法是 -(void)disocnnectOnlineMatch { [self.currOnlineMatch disconnect]; self.currOnlineMatch.delegate = nil; self.currOnlineMatch = nil; } 在Pla
-(void)disocnnectOnlineMatch {
[self.currOnlineMatch disconnect];
self.currOnlineMatch.delegate = nil;
self.currOnlineMatch = nil;
}
在Player1和Player2设备上,第一次调用此didChangeState函数,而不是在一段时间后再次调用Player3。它预计只会被调用一次,但对两名玩家来说都会调用两次
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
}
我在做什么?
断开比赛的最佳做法是什么
有时也会发生这种情况,调用didChangeState方法时会经过一定的延迟。而游戏中需要对断开连接的玩家进行一些更新
延迟响应的原因可能是什么
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
currOnlineMatch = match;
currOnlineMatch.delegate = self;
[PuzzleLogicManager sharedManager].onlineNextRound = 2;
[self setupRandomNumberToSend:2.0f];
[presentingViewController dismissViewControllerAnimated:YES completion:^() {
//NSLog(@"dismissed");
}];
}
请帮忙
提前感谢我认为这是iOS 6中引入的一个bug,因为我们也看到了它。我们不仅会收到重复的断开连接回调,而且有时还会收到来自仍然在游戏中并且移动良好的玩家的断开连接回调 为了解决这个问题,我所做的是在收到disconnect回调时验证GKPlayer是否真的断开了连接。我所做的就是检查我在比赛期间保存的GKMatch的全局副本,看看GKMatch的玩家是否还在那里。如果是这样,那么该玩家实际上没有断开连接,因此我可以忽略该消息:
NSString *id;
for (id in gCurrentMatch.playerIDs)
{
if ([id isEqualToString:playerID])
{
NSLog(@"player is NOT really disconnected!!!");
return; // just bail and ignore this
}
}