Handling CKErrors while using NSPersistentCloudKitContainer

312 views Asked by At

I have an app that uses Core Data, works great. I decided to try to use iCloud to sync data across multiple devices. I followed the basic steps of changing NSPersistentContainer to NSPersistenCloudKitContainer and adding iCloud capabilities, enabling CloudKit and Background Modes (remote notifications). With those few changes, data is syncing between devices as it should. Seemed very simple.

But, if the users iCloud storage gets full, the app continues to function and persist locally but sync stops (obviously) without notifying the user.

I understand it's a quotaExceeded error, but how would I go about accessing that error then handling it (and handling CKErrors in general)?

I feel like this NSPersistentCloudKitContainer is a wall that I can't get through to be able to handle CKErrors. I'm a beginner so maybe I'm missing something obvious but can't find any answers online.

Sticking with the quotaExceeded error situation:

  • Step 1 - CKError.Code.quotaExceeded occurs.
  • Step 2 - ???
  • Step 3 - Notify user that their iCloud storage is full.

What does step 2 look like?

1

There are 1 answers

3
Crew3339 On

Step 2 - Monitor NSPersistentCloudKitContainer.Event for event types and changes.

A solution was found in ggruen's answer (in their Misc section) in this question: NSPersistentCloudKitContainer: How to check if data is synced to CloudKit

From there I was able to handle CKErrors using the sample code in that answer.