由于给定的超时设置,我正在寻找有关如何取消cloudKit操作的帮助?我的情况是我使用CKModifyRecordsOperation上传一些更改到iCloud,如果失败,我会将那些失败的记录保存到本地存储。但有些事情,这个操作需要很长时间......
所以,我想在该操作上设置超时约60秒,然后如果超时,我将取消该操作。现在我只使用sleep func,虽然这不在主线程中,但它使每个添加的操作至少运行60秒。我知道这不是正确的解决方案。我的代码如下:
let uploadOperation = CKModifyRecordsOperation(recordsToSave: recordsToSave, recordIDsToDelete: recordIDsToDelete)
uploadOperation.modifyRecordsCompletionBlock = { (savedRecords, deletedRecordIDs, error) in
if let error = error {
...
CloudKitManager.persistentFailedRecords(saveFailed, deleteFailed)
}
}
CloudKitManager.privateDB.add(uploadOperation)
sleep(60)
if uploadOperation.isExecuting {
uploadOperation.cancel()
}
我做了一些关于操作超时的搜索,答案主要集中在NSURLSession,没有CloudKit操作的答案。我尝试使用自己的属性“timeoutIntervalForRequest”,但它不起作用。
任何帮助将不胜感激!谢谢!
你准确设置了吗?:
let operationConfiguration = CKOperation.Configuration()
operationConfiguration.timeoutIntervalForRequest = 60
operationConfiguration.timeoutIntervalForResource = 60
let fetchRecordZoneChangesOperation = CKFetchRecordZoneChangesOperation()
fetchRecordZoneChangesOperation.configuration = self.operationConfiguration
// etc...