1

First of all Check This to understand what i am doing

I did not get my answer in above question & still waiting for it.

Now new porblem is that when i click on back button using following code, methods of last ViewController are still running. It will use memory & keep processing untill it gets response(that`s what i want to do but if user press back then i want to stop all methods)

    [self.navigationController popViewControllerAnimated:YES];

How do i stop it?

Community
  • 1
  • 1
Jaymin Raval
  • 205
  • 2
  • 17
  • Well you add some asynchronous in the previous screen which you do not cancel. So they keep going. Also in you previous question you are creating a new session for each request. Just use one Session and on leaving a screen cancel all running requests. Or use a library like AFNetworking to handle the request for you. Then all you need to do is keep track of your requests. – rckoenes Mar 10 '14 at 11:12
  • @rckoenes Take one Global NSURLSession? How do i implement current code with afnetworking? – Jaymin Raval Mar 10 '14 at 11:16

1 Answers1

0

You need to do [getTryAgainTask cancel] (assuming getTryAgainTask is of type NSURLSessionDownloadTask) before you pop this controller. The download task is asynchronous and runs irrespective of the controller (that fired it) being deallocated. This might cause retain loops, leading the app to eventually crash. The code as of now, will go into an infinite loop. A better solution would be to keep a tab on the number of retries (say 3 times) and then prompt the user about the problem, asking if he/she would like to try again.

tipycalFlow
  • 7,514
  • 4
  • 31
  • 45
  • I tried Cancel on popviewController but it didn`t worked so i tried suspend which stops all task but is it right way? Retry Button option is good idea but i have to keep running this loop till i get data that`s client`s requirement. – Jaymin Raval Mar 10 '14 at 13:27
  • Suspending all tasks is also correct, if it doesn't also stop tasks that weren't started by this controller. Also, there must be a better way of providing the file url from backend itself, so that you do not have to keep iterating over *possible* file URLs. – tipycalFlow Mar 10 '14 at 15:37