根据.qualityOfService设置,CloudKit CKdatabaseOperation不会在模拟器中引发错误 [英] CloudKit CKdatabaseOperation does not throw error in simulator depending on .qualityOfService setting

查看:87
本文介绍了根据.qualityOfService设置,CloudKit CKdatabaseOperation不会在模拟器中引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上是在弄混CloudKit。我有2个问题需要协助/教育。

I am basically messing around with CloudKit. I have 2 questions that I would like some help/education with.

(1)当我尝试在关闭WiFi的模拟器中运行以下代码(模拟网络不可用)时,我希望引发网络不可用错误。但是,cloudKit不会引发任何错误,并且该函数也不执行任何操作,即不执行modifyRecordZonesCompletionBlock内的任何打印语句

(1) When I try to run the following code in the simulator with WiFi Turned off (To simulate network unavailability), I expect it to throw network unavailable error. However, cloudKit does not throw any error and the function does not do anything either i.e. does not execute either of the print statements inside the modifyRecordZonesCompletionBlock

self.container = CKContainer.default()
self.privateDB = self.container.privateCloudDatabase
let createZoneGroup = DispatchGroup()

createZoneGroup.enter()

let createZoneOperation = CKModifyRecordZonesOperation(recordZonesToSave: [customZone], recordZoneIDsToDelete: [])

createZoneOperation.modifyRecordZonesCompletionBlock = { (saved, deleted, error) in
if let theerror = error {
// Need to handle error
    print("Create Custom zone error \(theerror)")
} else {
    print("Custom Zone created")
}
    createZoneGroup.leave()
}

createZoneOperation.qualityOfService = .background
self.privateDB.add(createZoneOperation)

但是,当我更改 cre ateZoneOperation.qualityOfService default userInitiated ,然后抛出错误(如下):这是预期的行为。为什么是这样?仅仅是模拟器异常还是云工具包错误的抛出与服务的服务质量相关联,为什么?我在cloudkit API参考中找不到有关此行为的任何信息。

However, when I change the createZoneOperation.qualityOfService to default or userInitiated, it then throws an Error (below) as which is the expected behaviour. Why is this? Is it just a simulator anomaly or is the throwing of cloud kit errors tied to the operation quality of service and why? I cannot find any info in the cloudkit API reference for this behavior.

Create Custom zone error <CKError 0x60800005a2e0: "Partial Failure" (2/1011); "Failed to modify some record zones"; partial errors: {
    Main:__defaultOwner__ = <CKError 0x610000242910: "Network Unavailable" (3/NSURLErrorDomain:-1009); "The Internet connection appears to be offline.">
}>

(2)另外,我希望它会直线上升 Network Unavailable 错误而不是 Partial Failure failure错误,其中包含 Network Unavailable 错误。这是预期的行为吗?它是否总是抛出 Partial Failure 错误,然后必须将其展开以查找包含错误消息的文档?除非我没有查找,否则文档似乎缺乏任何解释。正确的地方。

(2) Also, I expected it to throw a straight up Network Unavailableerror rather than a Partial Failurefailure error with the Network Unavailable error wrapped inside it. Is this the expected behaviour? Does it always throw a Partial Failure error and then has to be unwrapped to find the containing error messages?The documentation appears to be incredibly lacking any explanation, unless I failed to look in the right place.

任何帮助将不胜感激。谢谢。

Any help would be very much appreciated. Thank you.

推荐答案

我要回答两个问题...

I'try to answer both questions...

没有模拟器错误或问题,您不会收到错误连接,因为.background服务质量意味着...

There's no simulator error or issue, you don't receive an error connection because .background quality of service means...


系统执行由用户启动的工作要比后台执行
的工作要早一些,后者可以推迟到更合适的时间。

The system performs work initiated by a user sooner than background work that can be deferred until a more optimal time.

也许这就是为什么您没有收到错误的原因,这是因为系统正在等待更好的网络状况,而您设置了.default或.userInitiate时,系统期望实时响应。

Maybe that's the reason why you don't receive the error, it's because system is waiting for a better network condition, while you set .default or .userInitiate the system expect a "real time" response.

iOS应用的能源效率指南

要模拟网络条件,请更好地使用网络链接Apple提供的Conditioner 工具。 在这里您可以找到有关它的更多信息

To simulate network conditions better use Network Link Conditioner tool by Apple. Here you could find more info about it.

我不确定,但是我认为部分失败是所有CKxxxxxOperation错误结果的通用包装。

I'm not sure about it but I think that Partial Failure is the common wrapper for all the CKxxxxxOperation error results.

它之所以有意义,是因为这些操作涉及1..N个CKRecords,其中一些可以正常完成,而其他一些则可以错误完成

It has sense because those operations involves 1..N CKRecords and some of them could finish ok, and others could finish with error

这篇关于根据.qualityOfService设置,CloudKit CKdatabaseOperation不会在模拟器中引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆