简体   繁体   English

CKQueryOperation可见性,取消和超时可能性

[英]CKQueryOperation visibility, cancellation and timeout possibilities

My application needs to run a CKQueryOperation using a CKDatabase. 我的应用程序需要使用CKDatabase运行CKQueryOperation。 This requires network access which is not always available. 这需要网络访问并不总是可用。

Once I add a CKQueryOperation to the CKDatabase that's about where my control stops. 一旦我将CKQueryOperation添加到CKDatabase,这是关于我的控件停止的位置。

Is there a way I can: 有没有办法可以:

  1. See of all pending operations specific to a CKDatabase. 查看特定于CKDatabase的所有待处理操作。
  2. Cancel an operation once I've added it to the CKDatabase? 将操作添加到CKDatabase后取消操作?
  3. Set a completion timeout so the operation doesn't stay pending if the network is preventing completion? 设置完成超时,以便在网络阻止完成时操作不会保持挂起状态?

I know I can do this with CKDatabase performQuery however I would prefer to use operations if possible, thanks in advance for your help! 我知道我可以用CKDatabase performQuery做到这一点但是我希望尽可能使用操作,提前感谢您的帮助!

For timeout you can set configuration object on the CKQueryOperation: 对于超时,您可以在CKQueryOperation上设置配置对象:

let config = CKOperation.Configuration()
config.timeoutIntervalForRequest = 5
config.timeoutIntervalForResource = 5

// Config operation
let operation = CKQueryOperation(query: query)
operation.configuration = config
operation.other_stuff..
operation.queryCompletionBlock = { (_, error: Error?) in
        guard error == nil else {
            // Handle timeout error here.
            return
        }
        ...
 }

Default timeout is 60 seconds. 默认超时为60秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM