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

Mat*_*erg 7 ios cloudkit

我有一个从节省时间到CloudKit的oplock错误.我似乎无法找出原因,但我怀疑当我从CloudKit仪表板手动编辑CKRecords然后从应用程序中获取并修改该记录时,就会发生这种情况.有没有人对oplock意味着什么以及我应该从哪里开始寻找解释?

这是错误

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

这是我的代码,请注意即使我不更改记录也会出现错误

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


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

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

     }

 }];
Run Code Online (Sandbox Code Playgroud)

Dan*_*lin 13

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

CKErrorCode.ServerRecordChanged /* The record was rejected because the version
                                   on the server was different */
Run Code Online (Sandbox Code Playgroud)

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

我发现如果非常有帮助解析所有CloudKit错误代码并按照Apple的评论添加到消息描述中...否则会收到错误消息,如:"client oplock error updates record" !!

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

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. */
}
Run Code Online (Sandbox Code Playgroud)


小智 5

我也有这个错误.

我通过确保我总是fetchRecordWithID先调用它然后saveRecordfetchRecordWithID完成处理程序内部调用来解决它.

请注意,fetchRecordWithID将返回CKErrorCodeUnknownItem新记录.务必妥善处理错误.我绕过了错误,以便我的代码将继续执行saveRecord,这将把记录插入CloudKit,(saveRecord当然,没有错误).