简体   繁体   English

CloudKit:已删除记录的 CKQueryOperation

[英]CloudKit: CKQueryOperation for deleted records

Is there a way to query CloudKit for recently deleted items (from a particular timestamp, perhaps), without using CKFetchRecordChangesOperation ?有没有办法在不使用CKFetchRecordChangesOperation情况下查询 CloudKit 中最近删除的项目(可能来自特定时间戳)? 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.我使用的是公共数据库,所以我不能使用自定义区域(这是CKFetchRecordChangesOperation的要求)......所以我需要一种方法来用公共数据库模拟这个。

I want to be able to efficiently update my local Core Data cache for changes in the CloudKit records.我希望能够针对 CloudKit 记录中的更改有效地更新我的本地 Core Data 缓存。 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.当您查询CloudKit记载,CKRecord似乎有一个creationDatemodificationDate财产,其中之一可以查询到最近看到创建/修改的记录,但不会针对在CloudKit删除的记录工作。

What would be an effective strategy here?什么是有效的策略?

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.我想到的一个解决方案是在 CKRecord 上维护一个“deletedDate”属性,因此当数据被“删除”时,您实际上并没有从 CloudKit 中删除记录,而只是更新此属性。 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).您还可以定期检查已删除日期超过 1 周或其他时间的记录,并在那时实际删除记录(尽管您想注意多个设备同时删除记录,以及其他边缘情况)。 Not the most elegant solution, but could work.不是最优雅的解决方案,但可以工作。 If there's a better option, would love to hear it.如果有更好的选择,很想听听。

One solution I have thought about is maintaining a "deletedDate" property on CKRecord,我想到的一个解决方案是在 CKRecord 上维护一个“deletedDate”属性,

This is not required这不是必需的

You want a CKFetchRecordZoneChangesOperation你想要一个CKFetchRecordZoneChangesOperation

Go watch the WWDC video here: https://developer.apple.com/videos/play/wwdc2014/231/在这里观看 WWDC 视频: https : //developer.apple.com/videos/play/wwdc2014/231/

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM