Cloud Kit发生错误时如何重新获取记录

时间:2019-09-05 16:08:21

标签: swift3 icloud cloudkit

Cloud WWDC说,当您获得CKError.changeTokenExpired时,可以通过将先前的服务器更改令牌设置为nil来重新获取更改。我尝试过这样的事情:

let operation = CKFetchRecordZoneChangesOperation()
operation.qualityOfService = .userInitiated
operation.recordZoneIDs = appDelegate.changedZoneIDs

let fetchOptions = CKFetchRecordZoneChangesOptions()
fetchOptions.previousServerChangeToken = nil
operation.optionsByRecordZoneID = [ recordZoneID : fetchOptions]

但是optionsByRecordZoneID已被弃用。那么如何将先前的服务器令牌传递给服务器并继续获取错误处理信息呢?

1 个答案:

答案 0 :(得分:0)

您应该在CKFetchRecordZoneChangesOperation()上使用实例属性configurationByRecordZoneID。

怎么样:

let operation = CKFetchRecordZoneChangesOperation()
operation.qualityOfService = .userInitiated
operation.recordZoneIDs = appDelegate.changedZoneIDs

let fetchOptions = CKFetchRecordZoneChangesOperation.ZoneConfiguration()
fetchOptions.previousServerChangeToken = nil

var zoneConfiguration: [CKRecordZone.ID : CKFetchRecordZoneChangesOperation.ZoneConfiguration] = [:]
for zoneID in operation.recordZoneIDs {
    zoneConfiguration[zoneID] = fetchOptions
}
operation.configurationsByRecordZoneID = zoneConfiguration