2

Is there a way to query CloudKit for recently deleted items (from a particular timestamp, perhaps), without using CKFetchRecordChangesOperation? I am using a public database so I can't use custom zones (which would be a requirement for CKFetchRecordChangesOperation) ... so I need a way to simulate this with public databases.

I want to be able to efficiently update my local Core Data cache for changes in the CloudKit records. When you query for CloudKit records, the CKRecord seems to have a creationDate and modificationDate property, which one can query for to see recently created / modified records, but that won't work for records that were deleted in CloudKit.

What would be an effective strategy here?

Z S
  • 7,039
  • 12
  • 53
  • 105
  • You can create a subscription that will report when a record is deleted? – user3069232 Mar 30 '16 at 06:27
  • 1
    The idea was to to use queries, since subscriptions rely on push notifications, which may or may not be reliable, and you can't use a pull-to-refresh feature to trigger a sync with subscriptions – Z S Mar 30 '16 at 17:28
  • No, there is no simple way to query what has been deleted. – rmaddy Mar 31 '16 at 04:23

2 Answers2

1

One solution I have thought about is maintaining a "deletedDate" property on CKRecord, so when data is 'deleted', you don't actually delete the record from CloudKit, instead just update this property. That will make it possible for other devices to query for records that have been deleted recently, so you can update the local cache. You can also periodically check for records that have deletedDate more than a 1 week or something and actually remove the records at that point (though you want to watch out for multiple devices deleting the records at the same time, and other edge cases). Not the most elegant solution, but could work. If there's a better option, would love to hear it.

Z S
  • 7,039
  • 12
  • 53
  • 105
  • 1
    Small tip. In my case I need to implement multi-user support facility for public database with Mac OSX application. So I integrated dateDeleted into Core Data entity as well, and added database synchronization (and subscription) in Mac OS X part. To hide "deleted" records simple predicate to Array controller is added. – Vladimir Vodolazkiy Jun 23 '16 at 07:39
1

One solution I have thought about is maintaining a "deletedDate" property on CKRecord,

This is not required

You want a CKFetchRecordZoneChangesOperation

Go watch the WWDC video here: https://developer.apple.com/videos/play/wwdc2014/231/

https://developer.apple.com/icloud/

amleszk
  • 6,192
  • 5
  • 38
  • 43
  • 1
    Note that this API is now deprecated. Instead, use CKFetchDatabaseChangesOperation to get the changes in a specific zone, which includes deletes. – Ben Scheirman May 31 '17 at 21:21