Can I stop/cancel an already running Asynchronous NSMutableURLRequest by setting it to nil?

StackOverflow https://stackoverflow.com/questions/23461940

Вопрос

As the question says, will the following help? I have not set any delegate to the request. Am I better off setting delegates?

request = nil;
Это было полезно?

Решение

No. NSMutableURLRequest can not 'run'. NSMutableURLRequest is just an object that stores url, body and some other options. To run it you should use NSURLConnection, example:

NSURLConnection* your_connection = [NSURLConnection connectionWithRequest:your_request delegate:delegate];

or NSURLSession which returns NSURLSessionTask, example:

NSURLSessionDownloadTask *sessionTask = [NSURLSession downloadTaskWithRequest:your_request];

To cancel connection/task you should call

[your_connection cancel];

or

[sessionTask cancel];

depending on what do you use.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top