Removing a GKTurnBasedMatch which is in an invalid state Removing a GKTurnBasedMatch which is in an invalid state ios ios

Removing a GKTurnBasedMatch which is in an invalid state


This is how I managed to remove all invalid matches.

I checked the status of the current participant, if it's invited, I called declineInviteWithCompletionHandler, otherwise I called participantQuitInTurnWithOutcome.

In both completion blocks, I then called removeWithCompletionHandler to remove the match.

This generated a few errors but the matches were still removed so my list is clean.

And here is a workaround on how to avoid getting to this state to begin with. This has the added benefit that the invitee never even get a notification if the inviter quits before finishing his/hers first turn.

In playerQuitForMatch, first end the turn and then in the completion handler, immediately quit the match. Like so,

[match endTurnWithNextParticipants:[NSArray arrayWithObject:nextParticipant]                                          turnTimeout:GKTurnTimeoutDefault                                            matchData:nil completionHandler:^(NSError *error) {                                                if (error) {                                                    NSLog(@"%@", error);                                                }                                                [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit                                                                     withCompletionHandler:^(NSError *error) {                                                                         if (error) {                                                                             NSLog(@"%@" ,error);                                                                         }                                                                     }];                                            }];


Unfortunately, I've run into the exact same error. To help others understand the problem, in hopes of researching a solution, you can recreate this by inviting a friend to a match, but then quitting the match during the first turn before you ever submit that turn to the invited player. Then, the hosting player removes the match from Game Center. On the invited player's device, they will have a match that looks like the one referenced above, that cannot be deleted. I've tried all types of workaround solutions.

I haven't had any luck yet, but I will update my answer with a solution if I find one. I'm currently trying to ship a Game Center game and so I have to find some way around this. I'll have a conclusion within the next day or two.

UPDATE:I went over my non-deleteable matches, and they are almost the same as yours except my player with the Invited status also has the match outcome of Won. It seems the key to put the match into an invalid state is to have one player status be Invited instead of Done, but have the match status be Ended. That's the common element between our two cases, and it's an edge case in Apple's bizantine Game Center code. It wouldn't surprise me if they simply screwed up this edge case and expected you to "just know" that you weren't supposed to put the players in that state (undoubtedly if you read their docs closely enough you'll be able to piece this together eventually).

My conclusion is that Apple has an edge case on their hands that goes unnoticed easily because it only can happen if you quit a new match, and only if you invite a friend, two cases you might not test often. Also, if you aren't setting match outcomes improperly I'm guessing it will never happen so they just never caught it.

Since I haven't shipped yet, I'm going to configure my app to detect matches in this state and ignore them. I'm going to report to the console a count of how many matches are in this state, just so I can ensure its not growing past this point. Then, I'm going to analyze my quitting code and make sure that in this edge case that I simply can never put a match into this state again. I think given what we know we've got to be proactive, and just suck up the fact that some matches slipped through.

Hopefully you haven't shipped yet, so the error case matches will be localized to the Game Center Sandbox environment. Actually, the bad matches are just localized to your test user in the Sandbox, so you could just throw away that user and start with a new user once you've corrected your issue. If you implement my above suggestions you should be able to confirm your app is working properly before taking this step.

If anyone can actually find a way to remove these error matches once they exist, please let us know, but I hope my suggestions and identification of the actual cause will be enough to help you proceed with your project.


I found the solution. For invalid matches just use -participantQuitOutOfTurn method and then -removeWithCompletionHandler method. It will be completely removed.