ios - 客户端oplock错误,在CloudKit中保存记录

标签 ios cloudkit

我在为 CloudKit 节省时间时发生了机会锁错误。我似乎无法找出原因,但我怀疑当我从 CloudKit 仪表板手动编辑 CKRecords 然后从应用程序获取和修改该记录时会发生这种情况。有没有人解释 oplock 的含义以及我应该从哪里开始寻找?

这是错误

Error Error saving record <CKRecordID: 0x79c42d60; 418deec9-ee5e-46b8-8877-606c14a5fe92:(_defaultZone:__defaultOwner__)> to server: client oplock error updating record

这是我的代码,注意即使我不改记录也会报错

    [self.publicDB saveRecord:self.currentUser completionHandler:^(CKRecord *record, NSError *error)
 {


     if(error)
     {
         NSLog(@"Error %@", error.localizedDescription);
     }

     else
     {
         NSLog(@"Saved access to Cloudkit");

     }

 }];

最佳答案

您收到此错误是因为服务器上用户记录的版本比您尝试更新的版本新。如果您获取错误代码 rawValue (14) 并将其映射到 CKErrorCode 枚举,您会看到它映射到:

CKErrorCode.ServerRecordChanged /* The record was rejected because the version
                                   on the server was different */

这就是为什么@shawnynicole 上面的回答在尝试保存用户记录之前通过 fetchRecordWithId 解决了这个问题。

我发现解析所有 CloudKit 错误代码并根据 Apple 的评论添加到消息描述是否非常有帮助...否则您会收到错误消息,例如:“客户端 oplock 错误更新记录” !!

CKError 代码和注释可以在 CloudKit header 中找到:

public enum CKErrorCode : Int { 
  case InternalError /* CloudKit.framework encountered an error.  This is a non-recoverable error. */
  case PartialFailure /* Some items failed, but the operation succeeded overall */
  case NetworkUnavailable /* Network not available */
  case NetworkFailure /* Network error (available but CFNetwork gave us an error) */
  case BadContainer /* Un-provisioned or unauthorized container. Try provisioning the container before retrying the operation. */
  case ServiceUnavailable /* Service unavailable */
  case RequestRateLimited /* Client is being rate limited */
  case MissingEntitlement /* Missing entitlement */
  case NotAuthenticated /* Not authenticated (writing without being logged in, no user record) */
  case PermissionFailure /* Access failure (save or fetch) */
  case UnknownItem /* Record does not exist */
  case InvalidArguments /* Bad client request (bad record graph, malformed predicate) */
  case ResultsTruncated /* Query results were truncated by the server */
  case ServerRecordChanged /* The record was rejected because the version on the server was different */
  case ServerRejectedRequest /* The server rejected this request.  This is a non-recoverable error */
  case AssetFileNotFound /* Asset file was not found */
  case AssetFileModified /* Asset file content was modified while being saved */
  case IncompatibleVersion /* App version is less than the minimum allowed version */
  case ConstraintViolation /* The server rejected the request because there was a conflict with a unique field. */
  case OperationCancelled /* A CKOperation was explicitly cancelled */
  case ChangeTokenExpired /* The previousServerChangeToken value is too old and the client must re-sync from scratch */
  case BatchRequestFailed /* One of the items in this batch operation failed in a zone with atomic updates, so the entire batch was rejected. */
  case ZoneBusy /* The server is too busy to handle this zone operation. Try the operation again in a few seconds. */
  case BadDatabase /* Operation could not be completed on the given database. Likely caused by attempting to modify zones in the public database. */
  case QuotaExceeded /* Saving a record would exceed quota */
  case ZoneNotFound /* The specified zone does not exist on the server */
  case LimitExceeded /* The request to the server was too large. Retry this request as a smaller batch. */
  case UserDeletedZone /* The user deleted this zone through the settings UI. Your client should either remove its local data or prompt the user before attempting to re-upload any data to this zone. */
}

关于ios - 客户端oplock错误,在CloudKit中保存记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36012376/

相关文章:

swift - CKFetchRecordsOperation 从不返回任何键

ios - 在 iOS 中使用 CloudKit 在 iCloud 中保留收据

cloudkit - 在 CloudKit 中创建指向多个 CKRecords 的引用列表

objective-c - 在 didSelectRow 上重新加载 UIPickerView

ios - 在 UITableViewCell 中委托(delegate) UICollectionView

ios - 在场景之间传递数据 (SpriteKit)

ios - 在 ios 中缓存视频

ios - 如何本地化 Cordova iOS 项目?

ios - 没有通知的 CloudKit CKSubscription?

cloudkit - 检查 CloudKit 数据库操作是否正在进行