The lifecycle of a turn based match looks like this:
- Create a match
- Invite others
- Others join
- Players take turns and pass the match object around (your game logic decides the order)
- Players send exchanges back and forth (optional)
- Players start leaving
- ----because they have been eliminated
- ----because they quit
- ----because they timed out
- Someone Wins
If you are not the active player, you are notified when steps 3, 4, 7, 8 and 9 happen by playerReceivedTurnEventForMatch
firing; however, as you can see from my answer here https://stackoverflow.com/a/34458493/1641444 playerReceivedTurnEventForMatch
fires for a lot of different conditions, and it doesn't tell you which one triggered it. You have to discern that based on the status of the players, which player is the active player, and whatever other information you track in the match object.
You are notified of #5 by playerReceivedExchangeRequest
firing (and Replies and Cancellation functions).
Your game logic will decide when to trigger #7. My preference is that the match object comes to the eliminated player, they are recognized as defeated, and calls participantQuitInTurnWithOutcome
Players decide when to trigger #8 by quitting, and the code calls either participantQuitInTurnWithOutcome
or participantQuitOutOfTurnWithOutcome
depending on their state.
Condition #9 is a real pain in the ass. Between limitations in the game design and outright bugs, timeouts can create several unrecoverable edge cases. Handling timeouts warrants its own full answer.
Finally, #10 is triggered by calling endMatchInTurnWithMatchData
. GKTurnBasedEventHandlerDelegate
and handleMatchEnded
were deprecated in IOS7. When using GKLocalPlayerListner
, you'll be notified of #10 by yet another occurrence of playerReceivedTurnEventForMatch
Edit--Clarifications based on followup questions:
Yeah, exactly. In your sendTurn function, when the game is over, don't call endTurnWithNextParticipant
. Instead, set the each participant's status to indicate who won and who lost, and then call endMatchInTurnWithMatchData
.
The other players will see playerReceivedTurnEventForMatch
fire. You can discern from the match status and the player status that the game is over and decide what actions to take for that recipient.