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

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

Pergunta

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;
Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top