Reputation: 2587
Suppose I have local cache with core data of a public CloudKit database. With a private database a device gets a list of changes that occurred while it was offline.
If I delete a record via the dashboard from the public database, then how will devices be made aware of this change? Zones and delta-lists are not available for public databases as far as I can tell. What's the trick here?
Upvotes: 2
Views: 615
Reputation: 4177
Detecting changes in the public database is also handled via subscriptions, but there are different types of subscriptions for different aspects of cloudkit. As noted at https://developer.apple.com/library/content/qa/qa1917/_index.html (emphasis added)
Note: The initializers for creating a CKSubscription object with a subscriptionID are deprecated, so use CKQuerySubscription, CKRecordZoneSubscription, or CKDatabaseSubscription on iOS 10.0+, macOS 10.12+, and tvOS 10.0+. Be aware that CKQuerySubscription is not supported in the shared database, and CKDatabaseSubscription currently only tracks the changes from custom zones in the private and shared database.
So, you'll need to use a CKQuerySubscription
to detect changes in the public database. With a CKQuerySubscription
you will specify a record type, optional search parameters (via NSPredicate
) and specify if the subscription should fire on creation, update, and/or deletion of the record.
The app will then receive a push notification when the trigger condition is met and is responsible to update the user's local data store as appropriate.
Upvotes: 4