I am trying to use CKQueryOperation
, rather then performQuery
on my CloudKit database.
Both work, but when using a CKQueryOperation I am not getting an error when the device is offline, but I do when using performQuery
Here is the bare bones my performQuery
example, database is my CKDatabase
database.performQuery(q, inZoneWithID: nil) { (records:[CKRecord]?, error:NSError?) in
if error != nil {
print(error!.localizedDescription)
return
}
}
An error is given when the device is offline, allowing me to prompt the user. The error is
The internet connection appears to be offline
However, I get no errors when I use a CKQueryOperation
let p = NSPredicate(format:"recordID IN %@", student.courses)
let q = CKQuery(recordType: String(Course), predicate: p)
let queryOperation = CKQueryOperation(query: q)
queryOperation.recordFetchedBlock = { record in
// not called without network connection - doesn't enter scope
print(record)
}
queryOperation.queryCompletionBlock = { (cursor: CKQueryCursor?, error: NSError?) in
// not called without network connection - doesn't enter scope
print(cursor)
print(error)
}
database.addOperation(queryOperation)
With a connection I receive my data for both methods so it is working as expected.
How / Where am I informed of error when using CKQueryOperation
?
Thanks
As per usual I post a bounty and find the answer within the next hour or 2. Not sure how I missed this originally but it contained the answer I was looking for.
So by adding this line
queryOperation.qualityOfService = .UserInitiated
something behind the scenes changes and we have some nice action within
queryOperation.queryCompletionBlock = { (cursor: CKQueryCursor?, error: NSError?) in
// We get an error message... Finally !!
print(error)
}
Couldn't find anything in the Apple Docs to hint at this either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With