1 Reply
      Latest reply on Jun 27, 2019 11:53 AM by .Nick
      tschmitz Level 1 Level 1 (0 points)

        Is there a way to pause or disable syncing via NSPersistentCloudKitContainer at runtime? I want to give my users the option to enable or disable syncing, but there doesn't seem to be a good way to do it. I tried reloading the persistent stores and setting the store description's cloudKitContainerOptions to nil, but if I do that after first initialization, I get an error:

         

        error: Store opened without NSPersistentHistoryTrackingKey but previously had been opened with NSPersistentHistoryTrackingKey - Forcing into Read Only mode

         

        Anyone know of another way to do this?

         

        I submitted a request via Feedback Assistant for a flag to enable or disable syncing (FB6156182). I know the user could theoretically go into the Settings app and enable or disable iCloud access for the app as a whole, but that's not very discoverable, and disables all iCloud access. I'm looking for something a little more fine-grained (limited to the NSPersistentCloudKitContainer) and that I could control in my app's UI.

        • Re: Toggle sync with NSPersistentCloudKitContainer
          .Nick Apple Staff Apple Staff (30 points)

          That error is because you also removed the history tracking option. Which you shouldn't do after you've enabled it.

           

          You can disable CloudKit sync simply by setting the cloudKitContainer options property on your store description to nil.

           

          However, you should leave history tracking on so that NSPersitentCloudKitContainer can catch up if you turn it on again.