首页 > 代码库 > iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”
iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”
iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”
http://stackoverflow.com/questions/13480611/has-anyone-experienced-crashes-when-using-alassetslibrary-in-a-background-thread
原因:
因为频繁的调用
[[ALAssetsLibrary alloc] init]
即使你相册关闭, 但如果频繁调用这句话, 在ARC方式下, 估计iOS也没有及时清空内存,
就会导致 “Too many contexts. No space in contextList.”
因此, 解决方式就是使用单例调用.
+ (ALAssetsLibrary *) defaultAssetsLibrary{ static dispatch_once_t pred = 0; static ALAssetsLibrary *library = nil; dispatch_once(&pred, ^{ library = [[ALAssetsLibrary alloc] init]; }); return library;}
或者我用了 DBCamera 库, 它已经提供了一个方法, 直接用也行.
ALAssetsLibrary *sharedLibrary = [[DBLibraryManager sharedInstance] defaultAssetsLibrary]; [sharedLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (group) { NSString *nameStr = [group valueForProperty:ALAssetsGroupPropertyName]; } failureBlock:^(NSError *error) { NSLog(@"failureBlock"); }];
测试后已经不那么容易崩溃了.
iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。