IOS: fetchRecordZoneChangesCompletionBlock not called when no internet connection

272 views Asked by At

I'm using the CloudKit in my app. To retrieve all changes from the iCloud I use the operation CKFetchRecordZoneChangesOperation. When I add this operation while I do not have an active internet connection the fetchRecordZoneChangesCompletionBlock is never called.

I do expect that this completion block is called with an error CKError.networkUnavailable.

I'm using swift 3.

I probably misunderstand some things. Can someone explain what I am missing?

1

There are 1 answers

0
Jonny On BEST ANSWER

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.

What you need to do is manually set your CKFetchRecordZoneChangesOperation's QoS to .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