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)错误说:
<CKError 0x174241e90:“更改令牌已过期”(21/1016); server message =“错误代码:RESET_NEEDED”; uuid = ...; container ID =“...”>
CKServerChangeToken 文档未提及有关重置令牌的任何信息,CloudKit仪表板不提供任何此类选项。
知道我应该做什么吗?
Swift 3.1, Xcode 8.3.3
I keep getting an error from CloudKit and I don't know what to do about it.
I'm tracking notifications from CloudKit like this:
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)And the error says:
<CKError 0x174241e90: "Change Token Expired" (21/1016); server message = "Error code: RESET_NEEDED"; uuid = ...; container ID = "...">
The CKServerChangeToken documentation don't mention anything about resetting the token, and the CloudKit dashboard doesn't offer any such option.
Any idea what I'm supposed to do?
最满意答案
此错误代码为CKErrorCodeChangeTokenExpired ,表明您需要重新同步更改。
https://developer.apple.com/documentation/cloudkit/ckerror/2325216-changetokenexpired
当更改令牌太旧或容器已重置(重置容器使旧的更改令牌无效)时,将返回此错误代码。
与此错误代码相关的注释包括:
(描述代码本身):
previousServerChangeToken值太旧,客户端必须从头开始重新同步
(在各种获取操作完成/更新块上):
如果服务器返回CKErrorChangeTokenExpired错误,则在执行此操作时用于此记录区域的serverChangeToken太旧,客户端应抛出其本地缓存并从nil serverChangeToken开始重新获取此记录区域中的更改。
This error code is CKErrorCodeChangeTokenExpired, and it's an indication that you need to re-sync your changes.
https://developer.apple.com/documentation/cloudkit/ckerror/2325216-changetokenexpired
This error code gets returned when the change token is too old, or the container has been reset (resetting the container invalidates old change tokens).
The comments related to this error code include:
(Describing the code itself):
The previousServerChangeToken value is too old and the client must re-sync from scratch
(On various fetch operation completion/updated blocks):
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.
更多推荐
发布评论