1

I am using sendAsynchronous request to receive data from multiple request at same time. It works great, i am able to load all the data. Even it is faster. But i want to cancel my request if the user cancels the request. so i have created a NSThread and using that thread i have created asynchronous request. When user clicks cancel button i just cancelled the thread.

But even after cancelling the thread the data is still getting loaded. So i want to stop those requests completely from loading data.

Even i used this,

[NSObject cancelPreviousPerformRequestsWithTarget:(id) selector:(selector) object:(id)]

but it doesn't work. Any help or suggestion will be appreciated.

Thanks in advance.

Sasi
  • 1,666
  • 2
  • 24
  • 44

1 Answers1

0

According to the documentation the NSUrlConnection class has it's own cancel method.

Note: Why are you using sendAsynchronousRequest in a own thread? The completion-handler will be executed when the request returns. While the request tries to reach the server and get an answer the main-thread shouldn't be blocked. I suggest to use either a synchronous request in a background thread or an asynchronous request in your main thread. Also be aware, that your thread doesn't terminate just by calling [NSThread cancel]

Community
  • 1
  • 1
Shelm
  • 91
  • 4
  • Ya i accept your answer, Even when i give asynchronous request in main thread i was not able to stop it. So can u give some example about canceling asynchronous request. – Sasi Sep 11 '12 at 04:57