The player takes multiple actions before completing a turn. After each action, I call saveCurrentTurnWIthMatchData, with the match data updated.
[gameMatch saveCurrentTurnWithMatchData: matchData completionHandler: ^(NSError *error){
if (error) {
NSLog(@"Error updating match = %@",error);
}
}];
On every other call I get "Error Domain=GKServerErrorDomain Code=5002 "status = 5002, Unexpected game state version expectedGameStateVersion='null'"
The GKTurnBasedMatch.state = 3 (GKTurnBasedMatchStatusMatching) in every call. I'm not changing this, I just check before the call. I have no idea if this is relevant.
Any suggestion what to try?
the "Unexpected game state version" error happens irregularly and is hard to reproduce -- although i can often reproduce it by calling
saveCurrentTurnseveral times in rapid succession. it would be useful to have clarity from Apple on this since it appears to be server side (but i'm not sure). i wrote a unit test that does stress testing onGKTurnBasedMatch.saveCurrentTurn. it fails irregularly but often up to 20% of the time.i have no full solution only a partial one. to partially mitigate the problem, you can wrap your
saveCurrentTurncalls in a task queue, that way they wait for the previous one to finish. not a solution, but helps.and here is the TaskQueue class i use