ios – 对游戏中心远程播放器退出的正确响应

我和两名参赛者A和B进行了回合比赛,目前是A轮. B通过拨打电话退出:
[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit ... etc.

就A的Game Center应用而言,与B的匹配仍然存在 – 匹配状态为GKTurnBasedMatchStatusOpen,匹配结果分别为GKTurnBasedMatchOutcomeNone和GKTurnBasedMatchOutcomeQuit.

从文档中,出现参与者A应该检测到并调用:

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

[self endMatchInTurnWithMatchData: ... etc.

然而,似乎没有通知参与者QuitOutOfTurnWthOutcome,并定期迭代通过每个匹配结束轮回感觉像一个kludge.

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

解决方法

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

首先你设置一个处理程序

[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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...