在后台线程中使用ALAssetsLibrary时是否有人遇到过崩溃? [英] Has anyone experienced crashes when using ALAssetsLibrary in a background thread?

查看:304
本文介绍了在后台线程中使用ALAssetsLibrary时是否有人遇到过崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ios应用程序在ios 5上没有以这种方式崩溃,现在在4或5 bg / fg周期后在启动时ios 6上始终崩溃。我已经将问题追溯到我对ALAssetsLibrary enumerateGroupsWithTypes的调用(应用程序在启动时同步到底层照片库)。对enumerateGroupsWithTypes的调用是在通过调度队列调用的后台线程中进行的,这样即使用户在完成之前将应用程序发送到bg,同步代码也可以完成。我收到的崩溃消息总是一样的:

I have an ios app which has not crashed in this way on ios 5 which is now crashing consistently on ios 6 on startup after 4 or 5 bg/fg cycles. I've traced the issue to my invocations of ALAssetsLibrary enumerateGroupsWithTypes (the app syncs to the underlying photo library whenever it starts up). The calls to enumerateGroupsWithTypes are made from within a background thread invoked via the dispatch queue so that the sync code can finish even if the user sends the app to the bg before it finishes. The crash message I receive is always the same:

* __addContextToList_block_invoke_0(),/ SourceCache / PhotoLibraryServices / MobileSlideShow-1647.5 / Sources中的断言失败/PLManagedObjectContext.m:1305

* Assertion failure in __addContextToList_block_invoke_0(), /SourceCache/PhotoLibraryServices/MobileSlideShow-1647.5/Sources/PLManagedObjectContext.m:1305

* 由于未被捕获而终止应用异常'NSInternalInconsistencyException',原因:'太多的上下文。 contextList中没有空格。'

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Too many contexts. No space in contextList.'

搜索这些错误消息并没有产生任何结果。由于直到应用程序开启/关闭至少5次才会发生这种情况,我认为这些块在完成时可能无法从苹果数据结构中正确删除?预先感谢任何潜在客户。

Googling for these error messages hasn't yielded anything. Since this never happens until the app has cycled on/off at least 5 times, I'm thinking that maybe the blocks are not being correctly removed from apple data structures when they finish? Thanks in advance for any leads.

更新:
经过更多调查后,这似乎与同步ALAssetsGroupLibrary有关。当我只同步ALAssetsGroupSavedPhotos或ALAssetsGroupLibrary中有0张照片时,不会发生崩溃。如果我只同步ALAssetsGroupLibrary并且那里至少有一张照片,就会发生这种情况。

UPDATE: After more investigating, this appears related to syncing ALAssetsGroupLibrary. The crash does not occur when i only sync ALAssetsGroupSavedPhotos or if there are 0 photos in ALAssetsGroupLibrary. It will occur if I sync only ALAssetsGroupLibrary and there is at least 1 photo in there.

推荐答案

事实证明这一切都是与为每个同步重新分配ALAssetsLibrary相关。
通过添加成员变量,崩溃似乎已经消失。

It turns out this has all been related to reallocating the ALAssetsLibrary for each sync. By adding a member variable instead, the crashing appears to have disappeared.

assetsLibrary = [[ALAssetsLibrary alloc] init];

assetsLibrary = [[ALAssetsLibrary alloc] init];

虽然这对我的代码来说显然是一种更有效/更好的设计,但我会说我遇到的问题表明ALAssetsLibrary和线程存在一些ARC问题。确保只分配一次!

While this is clearly a more efficient/better design for my code, I'd say the problems I've had indicate some ARC issue with ALAssetsLibrary and threading. Make sure to only allocate once!

这篇关于在后台线程中使用ALAssetsLibrary时是否有人遇到过崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆