我在我的应用中使用CloudKit。要从iCloud检索所有更改,我使用操作CKFetchRecordZoneChangesOperation。当我没有活动的互联网连接时添加此操作时,永远不会调用fetchRecordZoneChangesCompletionBlock。
我确实希望调用此完成块时出现错误CKError.networkUnavailable。
我正在使用swift 3。
我可能误解了一些事情。有人可以解释我错过的东西吗?
答案 0 :(得分:1)
CKOperation对象的默认服务质量等级为 NSQualityOfServiceUtility。此操作 级别被认为是自由裁量的,由系统安排 根据电池电量和其他因素获得最佳时间。上 iPhone,自由活动在低功耗模式下暂停 启用。
您需要做的是手动将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