为什么CloudKit CKOperations会超时?

时间:2018-11-28 11:50:13

标签: timeout icloud cloudkit ckoperation

我现在正在使用CKQueryOperation和CKModifyRecordsOperation来处理我在cloudKit中的记录。我发现无论我使用蜂窝网络还是wifi,有时都运行良好,但有时操作可能会超时,CKError.Code = 4。是我的代码:

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

任何帮助将不胜感激。

0 个答案:

没有答案