Search code examples
iosrecursioncloudkit

When CloudKit error occurs should client keep resending?


When client get a CKErrorRequestRateLimited client should perform operation again after RequestRateLimited sec. But what do you do when get some different error type i.e. CKErrorZoneBusy. How do you manage that case? I try to resend message recursively in every 10 sec, but it seems it does not help, because after error I get back every 10 sec the same error message:

\(error.localizedDescription) \(error.code) \(error.userInfo)"

Zone busy 23 Optional([NSDebugDescription: CKInternalErrorDomain: 2029, NSUnderlyingError: <CKError 0x15899950: "Unknown Error" (2029)>, NSLocalizedDescription: Zone busy])

Should I try 2-3 times and then break and reset persistent store / GUI accordingly? But then user will retry, and situation is the same.

I do not know it is matter or not, but I have uploaded several records with assets / images inside, a lot in short period of time, and one message quickly after the other. First messages were succeed, but at a point client started receive error.

What should be the procedure in this case?


Solution

  • As you can see in the documentation: https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CloudKit_constants/#//apple_ref/c/tdef/CKErrorCode

    ZoneBusy The server is too busy to handle this zone operation. Try the operation again in a few seconds. If you encounter this error again, increase the delay time exponentially for each subsequent retry to minimize server contention for the zone.

    So it looks like you are handling it already the way you should.

    How you handle this in your app is up to you. It's a matter of defining the right user interaction if a CloudKit save fails. I think a good interaction would be to show the user that there is a problem after a couple of seconds and if it still fails after 30 seconds of so, you should give the user an option to retry or to cancel.