设备离线时CKQueryOperation不返回错误 [英] CKQueryOperation not returning error when device offline
问题描述
我想在我的CloudKit数据库上使用 CKQueryOperation
,而不是 performQuery
。
两者都有效,但是当使用CKQueryOperation时,我在设备离线时没有收到错误,但是当我使用 performQuery
以下是我的 performQuery
示例,数据库是我的 CKDatabase
database.performQuery(q,inZoneWithID:nil){(记录:[CKRecord] ?,错误:NSError?) in
if error!= nil {
print(error!.localizedDescription)
return
}
}
当设备离线时给出错误,允许我提示用户。错误是
互联网连接似乎处于离线状态
但是,当我使用 CKQueryOperation
<$ p $时,我没有错误p>
设p = NSPredicate(格式:recordID IN%@,student.courses)
let q = CKQuery(recordType:String(Course),谓词:p)
let queryOperation = CKQueryOperation(query:q)
queryOperation.recordFetchedBlock = {记录在
//没有网络连接时调用 - 不输入范围
打印(记录)
}
queryOperation.queryCompletionBlock = {(游标:CKQueryCursor?,错误:NSError?)在
//没有网络连接时调用 - 不输入范围
打印(光标)
打印(错误)
}
database.addOperation(queryOperation)
通过连接,我收到两种方法的数据,因此它按预期工作。
我是怎么/在哪里使用 CKQueryOperation
时出错:
谢谢
按照惯例,我发布一笔赏金,在接下来的一小时内找到答案或者2.不确定我是怎么错过的这个最初但它包含我正在寻找的答案。
所以通过添加这一行
queryOperation.qualityOfService = .UserInitiated
幕后的一些变化,我们有一些不错的行动
queryOperation.queryCompletionBlock = { (游标:CKQueryCursor?,错误:NSError?)
//我们收到错误信息......最后!!
打印(错误)
}
在Apple中找不到任何内容文档暗示这一点。
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.
这篇关于设备离线时CKQueryOperation不返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!