我和两名参赛者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