CloudKit-更新记录:"客户端oplock错误"使用" saveRecord"更新记录时

时间:2016-02-06 11:32:12

标签: cloudkit ckrecord

我正在尝试将CKRecord更新为公共数据库。上传和下载非常有效。

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时出错:保存记录时出错CKRecordID:0x7f855dbcdb70; F3C192C8-6E81-493E-9E1A-75C5F3826F78 :( _ defaultZone: defaultOwner )到服务器:客户端oplock错误更新记录

这是什么意思?我该怎么做才能更新公共记录?

1 个答案:

答案 0 :(得分:1)

您有复制和粘贴问题。您从公共数据库获取,但您正在尝试保存到私有数据库。

改变这个:

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

为:

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