Swift 3.1,Xcode 8.3.3
我一直收到来自CloudKit的错误,我不知道该怎么办。
我正在跟踪来自CloudKit的通知:
let operation = CKFetchNotificationChangesOperation(previousServerChangeToken: previousChangeToken)
//Hold the notification IDs we processed so we can tell CloudKit to never send them to us again
var notificationIDs = [CKNotificationID]()
operation.notificationChangedBlock = { [weak self] notification in
guard let notification = notification as? CKQueryNotification else { return }
if let id = notification.notificationID {
notificationIDs.append(id)
}
}
operation.fetchNotificationChangesCompletionBlock = { [weak self] newToken, error in
if let error = error{
print(error) //<-- <!> This is the error <!>
}else{
self?.previousChangeToken = newToken
//All records are in, now save the data locally
let fetchOperation = CKFetchRecordsOperation(recordIDs: recordIDs)
fetchOperation.fetchRecordsCompletionBlock = { [weak self] records, error in
if let e = error {
print("fetchRecordsCompletionBlock Error fetching: \(e)")
}
//Save records to local persistence...
}
self?.privateDB.add(fetchOperation)
//Tell CloudKit we've read the notifications
let operationRead = CKMarkNotificationsReadOperation(notificationIDsToMarkRead: notificationIDs)
self?.container.add(operationRead)
}
}
container.add(operation)
错误说:
&lt; CKError 0x174241e90:“更改令牌已过期”(21/1016);服务器消息 =“错误代码:RESET_NEEDED”; uuid = ...; container ID =“...”&gt;
CKServerChangeToken
documentation未提及有关重置令牌的任何内容,CloudKit仪表板未提供任何此类选项。
知道我应该做什么吗?
答案 0 :(得分:1)
此错误代码为CKErrorCodeChangeTokenExpired
,表示您需要重新同步更改。
https://developer.apple.com/documentation/cloudkit/ckerror/2325216-changetokenexpired
当更改令牌太旧或容器已重置(重置容器使旧的更改令牌无效)时,将返回此错误代码。
与此错误代码相关的注释包括:
(描述代码本身):
previousServerChangeToken值太旧,客户端必须从头开始重新同步
(在各种获取操作完成/更新块上):
如果服务器返回CKErrorChangeTokenExpired错误,则在执行此操作时用于此记录区域的serverChangeToken太旧,客户端应抛出其本地缓存并从nil serverChangeToken开始重新获取此记录区域中的更改。