ios - GKTurnBasedMatch 不会前进到下一个玩家

标签 ios game-center gamekit gkturnbasedmatch

所以我的比赛有两名球员。当玩家 1 创建新的比赛时,我使用 endTurnWithNextParticipants 方法并为 nextParticipants 提供 GKTurnBasedMatch 的参与者数组属性,该属性有两个参与者。

但是在播放器 1 设备上,它一直说轮到你了。玩家 2 的设备上显示“轮到他们了”。

- (void)endTurnWithNextParticipants:(NSArray<GKTurnBasedParticipant *> *)nextParticipants
                        turnTimeout:(NSTimeInterval)timeout
                          matchData:(NSData *)matchData
                  completionHandler:(void (^)(NSError *error))completionHandler

有什么建议吗?

编辑:

下面是我如何使用 endTurnWithNextParticipantscurrentTurnBasedMatch 是 GKTurnBasedMatch 的一个实例。我确实验证了实例确实包含两个参与者(玩家 1 和 2)正确。并且完成没有任何错误。

[self.currentTurnBasedMatch endTurnWithNextParticipants:self.currentTurnBasedMatch.participants turnTimeout:GKTurnTimeoutDefault matchData:data completionHandler:^(NSError * _Nullable error) {
    MyNSLogSys2O(@"completion error:", error);  //default 1 week timeout
}];

最佳答案

我在这里看到两个问题:

首先,您要重新使用已存储在匹配项中的数组。这是一个不可变的数组,简单地将它再次传递回 endTurnWithNextParticipants 会导致各种奇怪的行为,这些行为有时可能会起作用,但大多数时候会导致非常奇怪的问题。我通过艰难的方式学到了这一点,我自己:GameCenter: endTurnWithNextParticipants not advancing .创建一个全新的数组并将参与者复制到其中。将该新数组传递给 endTurnWithNextParticipants

其次,我没有看到您试图调整数组中参与者的顺序以表明您想要更换为下一个玩家。 (无论如何,通过在比赛中重新使用不可变数组,它不会正常工作,但它仍然必须完成)如果你只有两个玩家,你可以使用我在上面的链接中使用的方法。如果你有两个以上的玩家,你需要做一些类似这个问题的公认答案:Game Center's Auto-match and endTurnWithNextParticipants

关于ios - GKTurnBasedMatch 不会前进到下一个玩家,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33962840/

相关文章:

ios - Swift:将 NSManagedObject 向上转换为 Entity 的子类

ios - 我如何回复 GKTurnBasedExchange? GKLocalPlayerListener 委托(delegate) receivedExchangeReplies 被间歇性地调用

ios - 确定 iOS 多人游戏中的最佳主机

iphone - GameCenter GKMatchmakerViewController 自动匹配不起作用,expectedPlayerCount 始终为 1,解决方案?

ios - GameCenter - 登录用户,如果他们已经输入了他们的凭据

iphone - GKSession 问题 - Objective-C GameKit

ios - 如何让 NSTimer 在强制退出后继续运行

iphone - 如何让两个 subview 相互交互?

ios - 在 Objective C 中使用代理同时快速发送请求

ios - 使用GKSession进行点对点时如何获得精确的时钟同步?