It would be good to be able to ask ObjectiveCDM to cancel an existing ObjectiveCDMDownloadTask.
I have a hacked together solution that appears to work:
// ObjectiveCDM.m
- (void) cancelTask:(ObjectiveCDMDownloadTask*)task
{
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
for(NSURLSessionDownloadTask *downloadTask in downloadTasks) {
if ([downloadTask.originalRequest.URL.absoluteString isEqualToString:downloadTask.currentRequest.URL.absoluteString]) {
[downloadTask cancel];
}
}
}];
[currentBatch removeTask:task];
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)downloadTask
didCompleteWithError:(NSError *)error {
if(error) {
if (error.code != NSURLErrorCancelled) {
NSString *downloadURL = [[[downloadTask originalRequest] URL] absoluteString];
ObjectiveCDMDownloadTask *downloadTaskInfo = [currentBatch downloadInfoOfTaskUrl:downloadURL];
if(downloadTaskInfo) {
[downloadTaskInfo captureReceivedError:error];
[currentBatch redownloadRequestOfTask:downloadTaskInfo];
[self postDownloadErrorToUIDelegate:downloadTaskInfo];
}//end if
}
}//end if
}
// ObjectiveCDMDownloadBatch.m
- (void) removeTask:(ObjectiveCDMDownloadTask*)task {
[urls removeObject:task.urlString];
[downloadInputs removeObject:task];
}
Thanks.
It would be good to be able to ask
ObjectiveCDMto cancel an existingObjectiveCDMDownloadTask.I have a hacked together solution that appears to work:
Thanks.