Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudkit: "ZoneId provided doesn't match target zone"

I have this piece of code:

func saveProfileForCheck(check: Check) {
    let toSave = CKRecord(recordType: "Check", zoneID: sharedStore.checksID!)
    let profile = check.profile as Profile!
    toSave.setValue(NSString(format: "%i", check.closed), forKey: "closed")
    toSave.setValue(check.date, forKey: "date")
    toSave.setValue(NSString(format: "%i", check.paid), forKey: "paid")
    toSave.setValue(CKReference(recordID: profile.dbRecordID, action: CKReferenceAction.DeleteSelf), forKey: "profile")

    let operation = CKModifyRecordsOperation(recordsToSave: [toSave], recordIDsToDelete: [check.id])
    operation.modifyRecordsCompletionBlock = { (savedRecords, deletedRecordIDs, error) in
        if error != nil {
            self.delegate?.cloudKitReturnedError(error!)
        } else {
            self.modifiedCheck(check, newRecord: savedRecords![0] as CKRecord )

        }
    }
    privateDB.addOperation(operation)
}

It's supposed to save a profile property on a Check object in my Checks RecordZone. When I trigger this function, I get this error:

 <CKError 0x7f8c2046d630: "Partial Failure" (2/1011); "Failed to modify some records"; uuid = EF4CCE3F-3CDB-4506-BA43-464D7D9BD0F6; container ID = "mycontainer"; partial errors: {
130BD962-295C-4601-9343-2E4F4014C8C7:(Checks:__defaultOwner__) = <CKError 0x7f8c2045c680: "Invalid Arguments" (12/2006); server message = "ZoneId provided doesn't match target zone">
... 1 "Batch Request Failed" CKError's omited ...

}>

I have attempted several things:

  • Checked whether the zoneID is actually correct, which it is.
  • Hard-coded the zoneID as a CKRecordZoneID object in the method.
  • Looked up the error on google and SO, which does not have result.

Please be aware that sharedstore.checksID is an actual ID instead of a string, which is created on app launch when all record zones are fetched.

How would I be able to solve this error? Any suggestion would be highly appreciated.

like image 871
Joris416 Avatar asked Oct 21 '15 10:10

Joris416


1 Answers

you have to set the zoneID on the operation wit something like:

    operation.zoneID = CKRecordZoneID(zoneName: sharedStore.checksID!, ownerName: "your name")

Update: As discussed below the .zoneID is only available on a CKQqueryOperation and not a CKModifyRecordsOperation

I believe it's only possible to set a CKReference to a record that is in the same zone. Is that the case? If not, then could you try saving the record without that reference?

From the documentation:

Treat each custom zone as a single unit of data that is separate from every other zone in the database. Inside the zone, you add records as you would anywhere else. You can also create links between the records inside a zone by using the CKReference class. However, the CKReference class does not support cross-zone linking, so each reference object must point to a record in the same zone as the current record

update: it is possible to add a reference across databases (public and private) provided the source and target of the reference are in the default zone.

like image 133
Edwin Vermeer Avatar answered Oct 15 '22 00:10

Edwin Vermeer