12

I have a turn-based match with two participants, A and B. It is currently A's turn. B quits out of turn by calling:

[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit ... etc.

As far as A's Game Center app is concerned, the match with B is still in play – the match status is GKTurnBasedMatchStatusOpen, and the match outcomes are GKTurnBasedMatchOutcomeNone and GKTurnBasedMatchOutcomeQuit respectively.

From the documentation, it appears that participant A should detect this and call:

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

[self endMatchInTurnWithMatchData: ... etc.

However, there seems to be no notification for participantQuitOutOfTurnWithOutcome, and periodically iterating through each match to end turns feels like a kludge.

What is the correct approach to ending these matches?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
jnic
  • 8,695
  • 3
  • 33
  • 47

1 Answers1

11

It has a nice solution :)

First of all you set a handler

[GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = self;

After which, you will get the callbacks

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

You need this method

handleMatchEnded:

To handle the match end on the opponent side.

Here is link to documentation https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/ImplementingaTurn-BasedMatch/ImplementingaTurn-BasedMatch.html#//apple_ref/doc/uid/TP40008304-CH15-SW12

l0gg3r
  • 8,864
  • 3
  • 26
  • 46
  • Thank you! I have `handleMatchEnded:` implemented but had clearly either missed that it covered this case, or been the victim of sandbox flakiness. The bounty is yours :) – jnic May 27 '14 at 15:21
  • Please note, that the event type is "push", it means that it will not work on "iOS Simulator", try to test on real devices. – l0gg3r May 29 '14 at 19:15