Pedro de Sá Pedro de Sá - 15 days ago 12
Swift Question

Error saving CKRecord and CKShare in CKModifyRecordsOperation

I'm trying to save a CKRecord (already created and saved to the database) and a new CKShare to it but I keep getting this error: Optional("Failed to modify some records"). Here is my code:

let csc = UICloudSharingController { controller, preparationCompletionHandler in

let share = CKShare(rootRecord: user)
share[CKShareTitleKey] = "My Share" as CKRecordValue
share.publicPermission = .readWrite

let mro = CKModifyRecordsOperation(recordsToSave: [user, share], recordIDsToDelete: nil)

mro.timeoutIntervalForRequest = 10
mro.timeoutIntervalForResource = 10

mro.modifyRecordsCompletionBlock = { records, recordIDs, error in
if error != nil {
print("ERROR IN MODIFY RECORDS COMPLETION BLOCK\n")
print(error?.localizedDescription)
}
preparationCompletionHandler(share,CKContainer.default(), error)
}
privateData.add(mro)
}
csc.availablePermissions = [.allowPrivate,.allowReadWrite]
self.present(csc, animated:true)
}


The problem is in this method: modifyRecordsCompletionBlock. Can somebody explain me why this is happening?

Thanks in advance!

Answer

I got it

All you have to do is create a private custom CKZone and save your CKRecord and CKShare in it, you cannot use the default zone cloud kit gives to you!

Comments