【问题标题】:Client oplock error, saving records in CloudKit客户端 oplock 错误,在 CloudKit 中保存记录
【发布时间】:2016-03-15 13:13:52
【问题描述】:

我在将时间保存到 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

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

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


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

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

     }

 }];

【问题讨论】:

  • 您能否向我们展示您的代码出错的地方以及您得到的错误的确切输出?
  • 好的,谢谢 - 更新了代码和错误
  • oplock 错误通常意味着您无权更新数据。您确定您的记录来自同一个公共数据库吗?记录是否由其他人创建,您是否设置了只能更新自己数据的安全设置?
  • 是的,它是默认容器,公共数据库,大多数时候代码都可以工作,我只是偶尔会收到这个错误(我怀疑记录被锁定了,可能有一段时间,当你编辑它在仪表板中)。
  • 您是否收到 ChangeTokenExpired 错误?您可以使用以下方法获取错误代码: let errorCode:CKErrorCode = CKErrorCode(rawValue: error!.code)! developer.apple.com/library/prerelease/ios/documentation/…

标签: ios cloudkit


【解决方案1】:

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

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

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

我发现如果按照 Apple 的 cmets 解析所有 CloudKit 错误代码并添加到消息描述中是否很有帮助...否则您会收到如下错误消息:“客户端 oplock 错误更新记录” !!

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

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. */
}

【讨论】:

【解决方案2】:

我也遇到了这个错误。

我通过确保始终先调用fetchRecordWithID,然后在fetchRecordWithID 完成处理程序中调用saveRecord 来解决此问题。

请注意,fetchRecordWithID 将返回 CKErrorCodeUnknownItem 以获取新记录。请务必正确处理错误。我绕过了错误,这样我的代码将继续运行到saveRecord,这会将记录插入到 CloudKit 中(当然,saveRecord 没有错误)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 2014-11-30
    • 2014-12-28
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多