Fast local update of CoreData+CloudKit with public database changes

552 views Asked by At

My app uses CoreData+Cloudkit with a public database.
By default, iCloud sync with a public database is only done at launch and then every half hour.
Since my app requires faster sync, all users are logged in to iCloud, and subscribed to iCloud changes. Thus, an iCloud modification of one user sends a notification to all other users. This works.

The problem:

The notification should now trigger an update of the local persistent store, i.e. an iCloud insert or update should download the respective iCloud record, and insert it or update it in the persistent store (deletes don’t happen).

Possible solutions:

  1. I could download the record from iCloud manually and then insert or update it in the managed context. However, an insert will then be treated as a new record, and uploaded later as a duplicate to iCloud. There will be a duplicate for every user who received the notification. While such dupes could be handled (there are only a few users), this is not so elegant.

  2. Much better is simply to trigger a re-mirroring, as it is anyway done during launch and every half hour. But I did not find any reasonable way to do this. I found one suggestion to toggle iCloud sync off and on (which should trigger a sync), but this gives me a client error (re-registration of a mirroring agent). I found another suggestion to swap the persistent stores (one with iCloud mirroring and one without) but this seems to me a terrible hack for my problem.

My question:

What is a reasonable way to update the local store with the iCloud changes?

1

There are 1 answers

2
Ing. Ron On

At the moment, the ck public db is only replicated at startup or after about 20 min