Pedro de Sá Pedro de Sá - 1 year ago 147
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 {
preparationCompletionHandler(share,CKContainer.default(), error)
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 Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download