IOS:没有互联网连接时不调用 fetchRecordZoneChangesCompletionBlock

IOS: fetchRecordZoneChangesCompletionBlock not called when no internet connection

我在我的应用程序中使用 CloudKit。要从 iCloud 检索所有更改,我使用操作 CKFetchRecordZoneChangesOperation。当我在没有活动的互联网连接时添加此操作时,永远不会调用 fetchRecordZoneChangesCompletionBlock。

我确实希望调用此完成块时出现错误 CKError.networkUnavailable。

我正在使用 swift 3.

我可能误解了一些事情。有人可以解释一下我错过了什么吗?

CKOperation Documentation

CKOperation objects have a default quality of service level of NSQualityOfServiceUtility. Operations at this level are considered discretionary, and are scheduled by the system for an optimal time based on battery level and other factors. On iPhone, discretionary activities are paused when Low Power Mode is enabled.

您需要做的是手动将 CKFetchRecordZoneChangesOperation 的 QoS 设置为 .userInitiated

// userInitiated: Used for performing work that has been explicitly requested by the user,
// and for which results must be immediately presented in order to allow for further user interaction.
// For example, loading an email after a user has selected it in a message list.
//
// set to userInitiated make sure the completion with error will immediately returned if currently no internet connection
zoneOperation.qualityOfService = .userInitiated