Skip to content

Task cancellation #6

@GregularExpressions

Description

@GregularExpressions

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions