When could CKError.Code.networkFailure happen? How to solve it?

137 Views Asked by At

I use CKQueryOperation to fetch records from iCloud. And I find that when the network environment of my iPhone is a cellular network, then the query operations offen failed with

CKError.Code.networkFailure: "available but CFNetwork gave us an error".

But I don't know why. Will this be related to my network operator?

let predicate = NSPredicate(value: true)
    let query = CKQuery(recordType: "RECORD", predicate: predicate)
    query.sortDescriptors = [NSSortDescriptor(key: "modificationDate", ascending: false)]
    let operation = CKQueryOperation(query: query)

// config
let config = CKOperation.Configuration()
config.timeoutIntervalForRequest = 10
config.timeoutIntervalForResource = 10
config.allowsCellularAccess = true
config.qualityOfService = .default
operation.configuration = config
operation.queuePriority = .normal

operation.recordFetchedBlock = { record in
    // handle every record
}
operation.queryCompletionBlock = { (cursor, error) in
    if let error = error {
        // handle error
    } else {
        // succeed
    }
}
self.privateDatabase.add(operation)
0

There are 0 best solutions below