wondering if anyone can help clear up an error that i get when calling GKTurnBasedMatch.saveCurrentTurn
. this error happens irregularly, but seems to be exacerbated by rapid successive calls to saveCurrentTurn
.
Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={GKServerStatusCode=5002, NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server., NSUnderlyingError=0x600002e1f480 {Error Domain=GKServerErrorDomain Code=5002 "status = 5002, Unexpected game state version expectedGameStateVersion='d9a7ea8c-f1de-4d35-8607-bc3c9bc1ebda' foundGameStateId='fc0f793d-4b88-4594-9b52-22ce2c1ae4fc' sessionId='1418932146:390cf165-49fc-40fb-aba7-08ff452d8500'" UserInfo={GKServerStatusCode=5002, NSLocalizedFailureReason=status = 5002, Unexpected game state version expectedGameStateVersion='d9a7ea8c-f1de-4d35-8607-bc3c9bc1ebda' foundGameStateId='fc0f793d-4b88-4594-9b52-22ce2c1ae4fc' sessionId='1418932146:390cf165-49fc-40fb-aba7-08ff452d8500'}}}
is there a way to avoid this error?
here is a unit test that demonstrates the above error -- error happens irregularly but frequently up to 20% of the time.
let total:Int = 100
var fail:Int = 0
func test_StressTest_saveCurrentTurn() {
guard let match = GKTurnBasedMatch_loadMatches()?.first else { return }
for i in 0..<total {
GKTurnBasedMatch_saveCurrentTurn(match, Data([UInt8(i)]))
}
print("failed \(fail) times out of \(total) total")
}
func GKTurnBasedMatch_saveCurrentTurn(_ match:GKTurnBasedMatch, _ payload:Data) {
let expectation = self.expectation(description:"expectation")
print("\(Self.self) \(#function)")
match.saveCurrentTurn(withMatch:payload) { error in
if let error = error {
print("\(error)")
self.fail += 1
}
expectation.fulfill()
}
wait(for:[expectation], timeout: 5)
}