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

后端 未结 4 1541
死守一世寂寞
死守一世寂寞 2021-02-15 13:41

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 invo

相关标签:
4条回答
  • 2021-02-15 14:05

    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];

    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!

    0 讨论(0)
  • 2021-02-15 14:12

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

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

    0 讨论(0)
  • 2021-02-15 14:17

    I suffered same issue:

    For short: While the ALAssetsLibrary instance is enumerating with types or the ALAssetsGroup instaces enumerated last step are enumerating assets, the ALAssetsLibrary instance and the ALAssetsGroup instances should never been changed before all the enumerating blocks are finished.

    0 讨论(0)
  • 2021-02-15 14:20

    ALAssetsLibrary enumeration runs in the main thread (see this SO answer). I suspect this is because the assets library may want to interact with the user for permissions to use location data (because photos have geotagging).

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

    0 讨论(0)
提交回复
热议问题