Gamecenter iOS 9 Gamecenter Gklocalplayerlistener Methods Not Called

How to detect when Game Center turn based match has ended in iOS9?

The lifecycle of a turn based match looks like this:

  1. Create a match
  2. Invite others
  3. Others join
  4. Players take turns and pass the match object around (your game logic decides the order)
  5. Players send exchanges back and forth (optional)
  6. Players start leaving
  7. ----because they have been eliminated
  8. ----because they quit
  9. ----because they timed out
  10. 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.

When does player(_:wantsToQuitMatch:) get called?

After several years of working with GKTurnBasedMatch, I have Never seen wantsToQuitMatch fire. Never. Not once.

The (massively overloaded) function, receivedTurnEventForMatch is the only function that will fire when a player joins or leaves. (See my answer at https://stackoverflow.com/a/34458493/1641444 for more information about when each of the functions fire). It's a pain because receivedTurnEventForMatch fires in many difference circumstances and it's left up to you to decipher which one triggered it.

This wasn't your question, but as you're just starting out with turn based matches, if you're not too heavily invested yet, I suggest you consider the new GKGameSession announced at WWDC this year. GKTurnBasedMatch has numerous constraints that can leave games stranded (can't be continued by any player). I'm just beginning to look into Game Sessions myself; however, at first glance, they give you much greater control plus a significantly larger match data object (512kB vs 64kB).



Related Topics



Leave a reply



Submit