Has anyone experienced crashes when using ALAssetsLibrary in a background thread?

I have an ios application that did not crash in this way on ios 5, which now constantly crashes on ios 6 when starting after 4 or 5 bg / fg cycles. I traced this problem with my ALAssetsLibrary enumerateGroupsWithTypes calls (the application is synchronized with the base photo library every time I start). EnumerateGroupsWithTypes calls are created from a background thread called through the send queue, so that the synchronization code can end even if the user sends the application to bg before it completes. The error message that I receive is always the same:

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

and

* Application termination due to the uncaught exception "NSInternalInconsistencyException", reason: "Too many contexts. There is no place in the list of contexts.

Google brought nothing for these error messages. Since this never happens until the application turns on / off at least 5 times, I think that maybe the blocks are not deleted from the Apple data structures after they are completed? Thanks in advance for any conclusions.

UPDATE: After a closer look, it looks like ALAssetsGroupLibrary synchronization. Failure does not occur when I only synchronize ALAssetsGroupSavedPhotos or if there are 0 photos in ALAssetsGroupLibrary. This will happen if I synchronize only ALAssetsGroupLibrary and there will be at least 1 photo.

+8
ios ios6 alassetslibrary
source share
4 answers

It turns out that all this was due to the redistribution of ALAssetsLibrary for each synchronization. By adding a member variable instead, the failure will disappear.

assetsLibrary = [[ALAssetsLibrary alloc] init];

Although this is clearly a more efficient / better design for my code, I would say that the problems I had indicate an ARC problem with ALAssetsLibrary and threads. Be sure to scroll once!

+7
source share

I had the same problem:

In short: while the ALAssetsLibrary instance lists the types or ALAssetsGroup tags listed last, the assets, the instances of the ALAssetsLibrary instance and ALAssetsGroup should never be changed before all the listed blocks are finished.

+1
source share

The ALAssetsLibrary enumeration is done in the main thread (see this SO answer ). I suspect this is because the asset library may want to interact with the user to obtain permissions to use location data (since the photos have geotags).

This may be the source of your problem if your code assumes that ALAssetsLibrary will continue to run in the background thread.

0
source share

You can check it out. I have this problem before. But fix it by creating a singleton ALAssetsLibrary object

https://stackoverflow.com/a/32693118/3103450

0
source share

All Articles