I am looking for help about how to cancel a cloudKit operation due to a given timeout setting? My case is I use CKModifyRecordsOperation upload some changes to iCloud, if failed, I will save those failed records to local storage. But something, the operation will take so long time...
So, I want to set a timeout about 60 seconds on that operation, then if timeout, I will cancel that operation. Now I just use sleep func, though this is not in main thread, it makes every added operation run at least 60s. I know this is not the right solution. My code like below:
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()
}
I did some search about timeout on an operation, the answer mainly focus on NSURLSession, no answer for CloudKit operation. And I tried with its own property "timeoutIntervalForRequest", but it doesn't work.
Any help will be appreciated! Thank you!