ios - 在 Game Center 中正确响应远程玩家退出

标签 ios objective-c game-center

我有一场回合制比赛,有两名参与者,AB。现在轮到 A 了。 B 通过调用退出:

[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit ... etc.

A 的 Game Center 应用程序而言,与 B 的比赛仍在进行中 – 比赛状态为 GKTurnBasedMatchStatusOpen ,匹配结果分别为GKTurnBasedMatchOutcomeNoneGKTurnBasedMatchOutcomeQuit

从文档中可以看出,参与者 A 应该检测到这一点并调用:

participantA.matchOutcome = GKTurnBasedMatchOutcomeWon;
participantB.matchOutcome = GKTurnBasedMatchOutcomeQuit;

[self endMatchInTurnWithMatchData: ... etc.

但是,似乎没有针对 participantQuitOutOfTurnWithOutcome 的通知,并且周期性地遍历每场比赛以结束回合感觉就像是一场困惑。

结束这些比赛的正确方法是什么?

最佳答案

它有一个很好的解决方案:)

首先你设置一个处理程序

[GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = self;

之后,你会得到回调

handleInviteFromGameCenter:
handleTurnEventForMatch:didBecomeActive:
handleMatchEnded:
handleTurnEventForMatch:didBecomeActive:
handleTurnEventForMatch:didBecomeActive:
player:receivedExchangeRequest:forMatch:
player:receivedExchangeCancellation:forMatch:
player:receivedExchangeReplies:forCompletedExchange:forMatch:

你需要这个方法

handleMatchEnded:

处理对方的比赛结束。

这里是文档链接 https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/ImplementingaTurn-BasedMatch/ImplementingaTurn-BasedMatch.html#//apple_ref/doc/uid/TP40008304-CH15-SW12

关于ios - 在 Game Center 中正确响应远程玩家退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23746271/

相关文章:

ios - 如果在 iOS7 中后台运行 cocos2d 2.1 应用程序同时观看 Game Center 屏幕(排行榜、成就)会崩溃

ios - 为什么我的 iOS 应用关联域端点没有被 Apple 调用?

ios - x86_64 的 undefined symbol - iOS - 64 位转换 - Xcode6

objective-c - 访问 NSUserDefaults 时是否需要使用委托(delegate)来维护 MVC 模式?

iphone - 支持多任务处理的 iOS 4 闹钟应用程序

objective-c - 如果我们保留或自动释放池怎么办?为什么?

ios - 替换 GKTurnBasedMatch 参与者属性中的玩家

iOS 上滑菜单

objective-c - Objective-C 运行时性能惩罚的细节

iphone - Gamecenter 显示名称在 Release模式下添加了引号