CloudKit。未调用 CKFetchRecordZoneChangesOperation 的令牌更改块

CloudKit. Token change block of CKFetchRecordZoneChangesOperation not called

我正在尝试实现与 CloudKit 的同步。 要从服务器获取更改,我正在使用 CKFetchRecordZoneChangesOperation。 然而,根本没有调用 recordZoneChangeTokensUpdatedBlock。 这是代码:

let options = CKFetchRecordZoneChangesOptions()
options.previousServerChangeToken = changesToken

let operation = CKFetchRecordZoneChangesOperation(recordZoneIDs: [paletteZoneId], optionsByRecordZoneID: [paletteZoneId:options])
operation.fetchAllChanges = true

operation.recordChangedBlock = {(record) in
   ...
}

operation.recordWithIDWasDeletedBlock = { (recordId,str) in
    ...
}

operation.recordZoneChangeTokensUpdatedBlock = { recordZoneId, token, data in
    print("new token")
    self.changesToken = token
}


operation.fetchRecordZoneChangesCompletionBlock = { error in
    ...
}

privateDB.add(operation)

因此结果操作不正常。其他块按预期调用。

文档说应该为每个区域调用令牌块,但根本没有调用。

非常感谢任何帮助。

非常感谢。

服务器更改令牌在不同的块中返回 - 您需要使用 recordZoneFetchCompletionBlock。

来自 CKFetchRecordZoneChangesOperation 头文件关于 recordZoneChangeTokensUpdatedBlock:

Clients are responsible for saving this per-recordZone serverChangeToken and passing it in to the next call to CKFetchRecordZoneChangesOperation.

Note that a fetch can fail partway. If that happens, an updated change token may be returned in this block so that already fetched records don't need to be re-downloaded on a subsequent operation.

recordZoneChangeTokensUpdatedBlock will not be called after the last batch of changes in a zone; the recordZoneFetchCompletionBlock block will be called instead

The clientChangeTokenData from the most recent CKModifyRecordsOperation issued on this zone is also returned, or nil if none was provided.

If the server returns a CKErrorChangeTokenExpired error, the serverChangeToken used for this record zone when initting this operation was too old and the client should toss its local cache and re-fetch the changes in this record zone starting with a nil serverChangeToken.

recordZoneChangeTokensUpdatedBlock will not be called if fetchAllChanges is NO.

获取函数定义以查看它。 (左键单击并 select 跳转到 recordZoneChangeTokensUpdatedBlock 上的定义

所以对于开发人员来说,这意味着,在巨大的请求(例如 1000 条记录)期间,如果出现某些错误,可以从中断点开始一个新的请求,并且只有其余的项目可以下载。实际上,今天,每收到 200 个项目后,就会调用此回调来处理大量请求,从而提供新的更改令牌。因此,可以以某种方式处理在发生错误之前收到的项目,并且可以稍后从该点触发更新。

最后,答案是:那个块被调用了一个巨大的请求。您可以通过创建数百个项目然后获取它们来尝试。