我在我的应用程序中使用 CloudKit,并开始遵循 WWDC 视频“CloudKit 最佳实践”中的最佳实践
首先要做的是检查我喜欢的更改,
let changesOperation = CKFetchDatabaseChangesOperation(previousServerChangeToken: databaseChangeToken)
changesOperation.fetchAllChanges = true
changesOperation.recordZoneWithIDChangedBlock = { self.recordZoneWithIDChanged($0) }
changesOperation.recordZoneWithIDWasDeletedBlock = { self.recordZoneWithIDWasDeleted($0) }
changesOperation.changeTokenUpdatedBlock = { self.changeTokenUpdate($0) }
changesOperation.fetchDatabaseChangesCompletionBlock = { self.fetchDatabaseChangesCompletion($0, isMoreComing: $1, error: $2) }
privateDatabase.add(changesOperation)
我正在为其设置提取的私有数据库中有记录,但我只得到changeTokenUpdatedBlock
和fetchDatabaseChangesCompletion
.
我是否正确地说,recordZoneWithIDChangedBlock
当我运行此操作并将我的私有数据库的默认区域传递到此块时,我应该期望看到被击中?
这意味着当我调用 my 时fetchDatabaseChangesCompletion
,没有什么可获取的,因为记录区域 ID 的数组为空:(注意,error
为 nil)
fileprivate func fetchDatabaseChangesCompletion(_ newToken: CKServerChangeToken?, isMoreComing: Bool, error: Error?)
{
if let error = error
{
// Handle error
return
}
let fetchZoneChangesOperation = CKFetchRecordZoneChangesOperation(recordZoneIDs: changedRecordZoneIDs,
optionsByRecordZoneID: nil)
fetchZoneChangesOperation.recordChangedBlock = { self.recordChanged($0) }
fetchZoneChangesOperation.recordWithIDWasDeletedBlock = { self.recordWithIDWasDeleted($0, string: $1) }
fetchZoneChangesOperation.recordZoneFetchCompletionBlock = { self.recordZoneFetchCompletion($0, newChangeToken: $1, clientSentChangeTokenData: $2, isMoreComing: $3, error: $4) }
fetchZoneChangesOperation.completionBlock = { self.fetchRecordZoneChangesCompletion() }
privateDatabase.add(fetchZoneChangesOperation)
}