Why CloudKit CKOperations offen timeout?

149 views Asked by At

I'm now using CKQueryOperation and CKModifyRecordsOperation to deal with my records in cloudKit.I find that whether I use cellular or wifi, sometimes it goes well, but sometimes the operations offen appears time out,CKError.Code = 4.Here are my codes:

let operation = CKModifyRecordsOperation(recordsToSave: [record], recordIDsToDelete: [])

    let config = CKOperation.Configuration()
    config.timeoutIntervalForRequest = 10
    config.timeoutIntervalForResource = 10

    operation.configuration = config
    operation.queuePriority = .veryHigh
    operation.modifyRecordsCompletionBlock = { [unowned self] (resultRecords, resultRecordIDs, error) in
        DispatchQueue.main.async {
            UIApplication.shared.isNetworkActivityIndicatorVisible = false
        }
        if let error = error {
            DispatchQueue.main.async {
                self.delegate!.failedWithError(error)
            }
        } else {
            let resultDevice = Device(record: resultRecords!.first!)
            self.deviceList.insert(resultDevice, at: 0)
            DispatchQueue.main.async {
                self.delegate!.succeedWithOperationMode(DeviceModel.OperationMode.insert, indexes: [])
            }
        }
    }
    privateDatabase.add(operation)
    UIApplication.shared.isNetworkActivityIndicatorVisible = true

Any help would be appreciated.

0

There are 0 answers