CloudKit- 更新记录:"client oplock error" 使用 "saveRecord" 更新记录时

CloudKit- update record: "client oplock error" when updating record using "saveRecord"

我正在尝试将 CKRecord 更新为 public 数据库。上传和下载效果很好。

func upDatePublicRecord() {  
        let database:CKDatabase = CKContainer.defaultContainer().publicCloudDatabase  

        if let myID = self.ID {  
            database.fetchRecordWithID(myID, completionHandler: { (myRecord, error) in  
                if error != nil {  

                    print("Error fetching record: \(error!.localizedDescription)")  

                } else {  

                    print("publicrecord fetched")  
                    myRecord!["name"] = self.name  
                  //and more code to change other properties  

                  //save back to iCloud  

                    CKContainer.defaultContainer().privateCloudDatabase.saveRecord(myRecord!) { [unowned self] (record, error) -> Void in  
                        dispatch_async(dispatch_get_main_queue()) {  
                            if error == nil {  

                            print("update success")  

                            } else {  
                                print("Error in update public: \(error!.localizedDescription)")}  
         }   
         }  
         }  
          })  
        }  
    }  

这适用于在 privateCloudDatabase 中更新,对于 public 数据库我收到此错误:

更新错误public:保存记录时出错 CKRecordID:0x7f855dbcdb70; F3C192C8-6E81-493E-9E1A-75C5F3826F78:(_defaultZone:defaultOwner) to server: client oplock error updating record

这是什么意思?我应该如何更新 public 条记录?

您遇到了复制和粘贴问题。您正在从 public 数据库中获取数据,但您正试图保存到私有数据库中。

改变这个:

CKContainer.defaultContainer().privateCloudDatabase.saveRecord(myRecord!) { [unowned self] (record, error) -> Void in  

至:

CKContainer.defaultContainer().publicCloudDatabase.saveRecord(myRecord!) { [unowned self] (record, error) -> Void in