In my turn based game, I receive the following error indicating the session is in an invalid state and that the game is not active:
2014-06-26 15:46:04.684 myApp[14498:60b] Error Domain=GKErrorDomain Code=24
"The requested operation could not be completed because the session is in an invalid state."
UserInfo=0x16d074a0 {GKServerStatusCode=5101, NSUnderlyingError=0x16d09fb0
"The operation couldn’t be completed. status = 5101, Game is not active, session state is Complete",
NSLocalizedDescription=The requested operation could not be completed because the session is in an invalid state.}
This error occurs when I call endMatchInTurnWithMatchData:completionHandler: (at this point in time, its the local player's turn and he is Quitting the game). However, I do not understand what is wrong with the current state. Prior to calling this method, I printed the match object. Here is the content:
currentMatch object is:
<GKTurnBasedMatch 0x16d5e690 - matchID:c53a9ef1-d4ce-4da3-a2f3-9220df917615 bundleID:com.myCompany.myApp
status:GKTurnBasedMatchStatusOpen message:'' creationDate:2014-06-26 20:43:17 +0000
currentParticipant:
<GKTurnBasedParticipant 0x16d430d0 - playerID:G:1386520835 (local player) status:Done matchOutcome:Quit lastTurnDate:2014-06-26 20:43:35 +0000 timeoutDate:(null)>
participants:
<GKTurnBasedParticipant 0x16d430d0 - playerID:G:1386520835 (local player) status:Done matchOutcome:Quit lastTurnDate:2014-06-26 20:43:35 +0000 timeoutDate:(null)>,
<GKTurnBasedParticipant 0x16d526c0 - playerID:G:109161898 status:Active matchOutcome:Won lastTurnDate:2014-06-26 20:43:54 +0000 timeoutDate:(null)> matchData.length:712 matchDataMaximumSize:65536 exchanges:(null)>
As you can see, the status of the match is GKTurnBasedMatchStatusOpen. If I'm not mistaken, that tells me that the game IS active. Also, each participant has a matchOutcome that is not "None" which is a requirement before sending endMatchInTurnWithMatchData:completionHandler:.
Here is my sequence of code to end the match when this local player quits:
[currentMatch participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit nextParticipants:currentMatch.participants turnTimeout:1.0 matchData:data completionHandler:nil];
NSLog(@"currentMatch object is: %@", currentMatch);
[currentMatch endMatchInTurnWithMatchData: data
completionHandler: ^(NSError *error) {
if (error) {
NSLog(@"%@", error);
}
else {
NSLog(@"match ended successfully");
}
}];
Please tell me what is wrong with my approach to end the match or with the state of the session/match that is causing this error or suggest to me what else I should verify to determine the source of the problem.