Tom Tallak Solbu
Tom Tallak Solbu

Reputation: 559

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

I am trying to update a CKRecord to public databse. Up and downloading works very well.

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)")}  
         }   
         }  
         }  
          })  
        }  
    }  

This works for updating in privateCloudDatabase, for the public database i get this error:

Error in update public: Error saving record CKRecordID: 0x7f855dbcdb70; F3C192C8-6E81-493E-9E1A-75C5F3826F78:(_defaultZone:defaultOwner) to server: client oplock error updating record

What does this mean? What should I do to update a public record?

Upvotes: 0

Views: 891

Answers (1)

rmaddy
rmaddy

Reputation: 318814

You have a copy and paste problem. You are fetching from the public database but you are trying to save to the private database.

Change this:

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

to:

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

Upvotes: 1

Related Questions