4

Hi to all the CloudKit users:

I had a horrible time trying to find out why CKDatabaseOperation wouldn't give any feedback. No errors, no callbacks when saving CKRecords on cellular.

Could you please let me know what is your opinion regarding this?

Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
ferdyyy
  • 515
  • 4
  • 16
  • Possible duplicate of [iOS 9 CloudKit: query does not return anything while connected to cellular network](http://stackoverflow.com/questions/32493698/ios-9-cloudkit-query-does-not-return-anything-while-connected-to-cellular-netwo) – rmaddy Dec 10 '15 at 03:33

1 Answers1

8

Someone in the Developer Forums of Apple found a solution: https://forums.developer.apple.com/thread/20047

the magic happens when setting qualityOfService = .UserInitiated

Example:

let publicDB = CKContainer.defaultContainer().publicCloudDatabase    
let operation = CKModifyRecordsOperation(recordsToSave: [aRecord], recordIDsToDelete: nil)

operation.allowsCellularAccess = true
operation.qualityOfService = .UserInitiated // <----- THATS THE CELLULAR FIX

operation.perRecordProgressBlock = {(record, progress) in
    print("Progress: \(Int(progress*100.0))%")
}
operation.perRecordCompletionBlock = {(record, error) in
    print("Upload complete") //Add awesome error handling here
}
publicDB.addOperation(operation)
ferdyyy
  • 515
  • 4
  • 16