0

I have a problem with an app where I implemented an NSOperationQueue. It seems that pressing the close button of the iPad makes the UI freeze. The app itself is still running in the background, the UI is updated, it's just that it won't answer to touches or rotation anymore and it doesn't get closed as it should be.

I have an update module that downloads quite a long list of xml files and saves them on the device. The operation queue has a MaxConcurentOperations value of 2. Usually everything works fine, the app runs fine and dandy, responding to my touches and rotation UNTIL I press the device's button. After this, the UI simply freezes. The progress is still updated (an UILabel), recurrent animations are still displayed, but the app is not closed until all the operations are done.

I'm not calling waitUntilAllOperationsAreFinished on my queue so I don't know what might be causing this.. So far, I've only made tests on a first generation iPad, with iOs 5.0

If anyone can provide me with some tips, I'll really appreciate it. If necessary, I can post the NSOperationQueue and NSOperation class codes, but somehow I have the feeling this about me approaching this wrongly, and not about a faulty line of code

[edit] I also use a timer to periodically check on the download status, but I noticed that not calling the timer doesn't eliminate the problem

self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(xmlDownloaded) userInfo:nil repeats:YES];

[edit2] After some further research, I made sure that my operations are concurrent and just to be sure, I changed the way I added my operations to the queue. Instead of

[downloadQueue addOperation:op];

I added them to a mutable array called "operations" and in the end I used

[downloadQueue addOperations:operations waitUntilFinished:NO];

but my app still freezes when I press the close button...

BBog
  • 3,630
  • 5
  • 33
  • 64

2 Answers2

1

Wild guess, you are locking the main thread waiting for your operation to complete / you are destroying your operation delegate on viewWillDisappear?

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • No, the only similar things I do are to cancel the queue in the dealloc (setSuspended/cancelAllOperations/release) and suspend it when the internet connection is down. Also, I do not have a delegate for my operations – BBog May 22 '12 at 10:12
0

It seems there was another function causing this, even though I don't understand why...

I had a label animation

CABasicAnimation *fadey = [CABasicAnimation animationWithKeyPath:@"opacity"];

[fadey setToValue:[NSNumber numberWithFloat:0.35f]];

fadey.repeatCount = HUGE_VALF;

[fadey setAutoreverses:YES];

[fadey setDuration:0.6f];

This small function was causing the app to wait until all the operations were finished in order to close the app. The weird part is that the function was not even called in with the NSOperations, but before them Again, I have no idea why... everything breaks when I press the close button, otherwise there are no problem. So if anyone else runs into a similar issue, it might help to check for some repeating animations

Community
  • 1
  • 1
BBog
  • 3,630
  • 5
  • 33
  • 64