NSOperationQueue 在 IOS 中崩溃
我有一个使用 NSOperationQueue 在后台下载图像的项目。到目前为止,它可以在 iOS 4.3 的设备上运行。但是,如果我使用基础 sdk 4.3 或 5 构建应用程序并在使用 IOS5 的设备上运行该应用程序,则该应用程序会崩溃。当应用程序启动时,它会将 NSOperation
对象添加到队列中以下载图像。如果在中间按下后退按钮,我会取消 NSOperation,它会崩溃并在控制台上显示以下跟踪:
#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 ()
并打印“ResourceLoadOperation isFinished = YES,而不会由它所在的队列启动” 如果我评论取消方法调用,应用程序不会崩溃。 IOS5 的 NSOperation
更改有任何更新吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在针对 iOS 5 构建时遇到了同样的问题。我最终创建了一个名为
operationStarted
的标志,默认情况下为NO
,然后我切换为YES
当调用start
方法时。然后,在我的finish
方法(生成 KVO 通知的地方)中,我在触发通知之前检查了标志的值。标志定义如下所示:
start
方法:当操作完成或取消时调用的我的
finish
方法:最终为我解决了问题。希望它对其他人有帮助。
I had this same problem when building against iOS 5. I ended up creating a flag named
operationStarted
that wasNO
by default and I toggled toYES
when thestart
method was called. Then in myfinish
method (where I generate the KVO notifications), I checked the value of the flag before firing the notifications.The flag definition looks like this:
The
start
method:My
finish
method which is called when the operation is complete or cancelled:That ended up resolving the issue for me. Hope it helps someone else.