1

我正在实现一个自定义 matchmaker 视图控制器,并使用 GKMatchmaker 以编程方式使用以下方法为两个玩家找到匹配项:

[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *thisMatch, NSError *error)

我的自定义 matchmaker 视图控制器有一个按钮,允许玩家通过 [[GKMatchmaker sharedMatchmaker] cancel] 取消比赛。

当玩家 1 取消比赛时,有时 GKMatch 已经与玩家 2 创建。我如何通知玩家 2 玩家 1 已取消比赛并开始搜索另一场比赛?

我想答案可能在于 GKMatchmakerViewController 类和调用委托方法 matchmakerViewControllerWasCancelled 之前的代码。有谁知道我怎么能得到这个?

4

1 回答 1

1

在玩了这个之后,我意识到当玩家在创建 GKMatch 之后但在玩家连接之前取消比赛时,以下函数中的 GKPlayerStateDisconnected 需要很长时间才能被调用:

- (void)match:(GKMatch *)theMatch player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state

如果 GKMatch 已创建但玩家未连接,我会在约 15 秒后再次调用 findMatchForRequest 函数来解决此问题。

有兴趣知道人们是否有更优雅的解决方案。

于 2013-04-08T08:15:20.363 回答