I have a project which downloads images in background using NSOperationQueue. It was working until now on devices with IOS 4.3. However if I build the app with base sdk 4.3 or with 5 and run the app on device with IOS5, the app crashes. When app is launched, it adds NSOperation objects into queue for downloading the images. If in between I press back button, I cancel the NSOperation and it crashes and displays following trace on console:
#0 0x004727b7 in ____NSOQSchedule_block_invoke_0 () #1 0x026a5618 in _dispatch_call_block_and_release () #2 0x026a7a10 in _dispatch_worker_thread2 () #3 0x974bb781 in _pthread_wqthread () #4 0x974bb5c6 in start_wqthread ()
and prints “ResourceLoadOperation isFinished = YES without being started by the queue it is in”
If I comment the cancel method call, app doesnot crash.
Is there any updates on the NSOperation changes for IOS5?
I had this same problem when building against iOS 5. I ended up creating a flag named
operationStartedthat wasNOby default and I toggled toYESwhen thestartmethod was called. Then in myfinishmethod (where I generate the KVO notifications), I checked the value of the flag before firing the notifications.The flag definition looks like this:
The
startmethod:My
finishmethod which is called when the operation is complete or cancelled:That ended up resolving the issue for me. Hope it helps someone else.