CloudKit Error: Change Token Expired, Reset Needed
CloudKit Error: Change Token Expired, Reset Needed
Swift3.1,Xcode8.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)
错误说:
<CKError 0x174241e90: "Change Token Expired" (21/1016); server message
= "Error code: RESET_NEEDED"; uuid = ...; container ID = "...">
CKServerChangeToken
documentation 没有提及任何关于重置令牌的内容,CloudKit 仪表板也没有提供任何此类选项。
知道我应该做什么吗?
此错误代码是 CKErrorCodeChangeTokenExpired
,表示您需要重新同步您的更改。
https://developer.apple.com/documentation/cloudkit/ckerror/2325216-changetokenexpired
当更改令牌太旧或容器已重置(重置容器会使旧的更改令牌无效)时返回此错误代码。
与此错误代码相关的注释包括:
(描述代码本身):
The previousServerChangeToken value is too old and the client must re-sync from scratch
(在各种获取操作 completion/updated 块上):
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.
Swift3.1,Xcode8.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)
错误说:
<CKError 0x174241e90: "Change Token Expired" (21/1016); server message = "Error code: RESET_NEEDED"; uuid = ...; container ID = "...">
CKServerChangeToken
documentation 没有提及任何关于重置令牌的内容,CloudKit 仪表板也没有提供任何此类选项。
知道我应该做什么吗?
此错误代码是 CKErrorCodeChangeTokenExpired
,表示您需要重新同步您的更改。
https://developer.apple.com/documentation/cloudkit/ckerror/2325216-changetokenexpired
当更改令牌太旧或容器已重置(重置容器会使旧的更改令牌无效)时返回此错误代码。
与此错误代码相关的注释包括:
(描述代码本身):
The previousServerChangeToken value is too old and the client must re-sync from scratch
(在各种获取操作 completion/updated 块上):
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.