Removing a GKTurnBasedMatch which is in an invalid state
game-center, gamekit, ios
Solution
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);
}
}];
}];
Problem
I am doing some experimentation to try to learn about GameKit and I made a simple game and an interface which lists my player's matches. I am trying to add the ability to remove games using the `removeWithCompletionHandler:` method on the match, but I am having trouble removing a `GKTurnBasedMatch` which seems to have entered an invalid state. A po of the match in question prints: ``` $0 = 0x1d590d20 <GKTurnBasedMatch 0x1d590d20 id:858d8257-cc49-4060-b1d8-38c09a929e3c status:Ended message: taken:2013-03-08 18:08:47 +0000 created:2013-03-08 03:24:14 +0000 current:<GKTurnBasedParticipant 0x1d58c020 - id:G:1717956303 (local player) status:Invited outcome:None lastTurn:(null)> participants: <GKTurnBasedParticipant 0x1d58bc90 - id:G:1717239488 status:Done outcome:Quit lastTurn:2013-03-08 18:08:47 +0000> <GKTurnBasedParticipant 0x1d58c020 - id:G:1717956303 (local player) status:Invited outcome:None lastTurn:(null)> > ``` Which seems to indicate that the match has been ended. However, one of the participants has the outcome:None, which I am led by the docs to believe is invalid for an ended game. Trying to simply remove the game gives: The requested operations could not be completed because one or more parameters are invalid. While trying to set the outcomes and end the game gives: The requested operation could not be completed because the session is in an invalid state. I thought perhaps I could not remove the game because the local player is the active participant, but both `participantQuitInTurnWithOutcome:...` and `endTurnWithNextParticipants:...` both give the error: The requested operation could not be completed because the session is in an invalid state. as well. Am I doing something wrong or did I somehow create an unremovable game? P.S. I am also unable to remove the games through the Game Center provided interface, where they are listed under the "Game Over" section.