Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在UICollectionView中使用AlassetLibrary检索图像时,某些用户的ios应用程序崩溃_Objective C_Iphone_Uicollectionview_Crash Reports_Alassetlibrary - Fatal编程技术网

Objective c 在UICollectionView中使用AlassetLibrary检索图像时,某些用户的ios应用程序崩溃

Objective c 在UICollectionView中使用AlassetLibrary检索图像时,某些用户的ios应用程序崩溃,objective-c,iphone,uicollectionview,crash-reports,alassetlibrary,Objective C,Iphone,Uicollectionview,Crash Reports,Alassetlibrary,我有一个ios应用程序,我可以使用ALAssetLibrary访问图库中的图像来填充UICollectionView。对于印度(我的祖国)的测试用户来说,它工作正常,但在我们的美国客户机的设备上不工作。当客户机打开集合视图时,它崩溃,出现以下错误: Fatal Exception: NSInvalidArgumentException *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil Thread : Fatal Exc

我有一个ios应用程序,我可以使用ALAssetLibrary访问图库中的图像来填充UICollectionView。对于印度(我的祖国)的测试用户来说,它工作正常,但在我们的美国客户机的设备上不工作。当客户机打开集合视图时,它崩溃,出现以下错误:

Fatal Exception: NSInvalidArgumentException *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil Thread : Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x182ef9900 __exceptionPreprocess 1 libobjc.A.dylib 0x182567f80 objc_exception_throw 2 CoreFoundation 0x182de3134 CFStringConvertNSStringEncodingToEncoding 3 QuikCom 0x10009e594 __27-[ImageSelector loadAssets]_block_invoke_2 (ImageSelector.m:65) 4 AssetsLibrary 0x18c74ba4c __62-[ALAssetsGroup _enumerateAssetsAtIndexes:options:usingBlock:]_block_invoke147 5 CoreFoundation 0x182df0370 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke 6 CoreFoundation 0x182df0268 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] 7 AssetsLibrary 0x18c74b520 -[ALAssetsGroup _enumerateAssetsAtIndexes:options:usingBlock:] 8 QuikCom 0x10009e4a4 __27-[ImageSelector loadAssets]_block_invoke (ImageSelector.m:60) 9 AssetsLibrary 0x18c74d8e4 __68-[ALAssetsLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:]_block_invoke_3 10 CoreFoundation 0x182df0370 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke 11 CoreFoundation 0x182df01e0 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] 12 AssetsLibrary 0x18c74d83c __68-[ALAssetsLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:]_block_invoke_2 13 libdispatch.dylib 0x18294d630 _dispatch_call_block_and_release 14 libdispatch.dylib 0x18294d5f0 _dispatch_client_callout 15 libdispatch.dylib 0x182952cf8 _dispatch_main_queue_callback_4CF 16 CoreFoundation 0x182eb0bb0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ 17 CoreFoundation 0x182eaea18 __CFRunLoopRun 18 CoreFoundation 0x182ddd680 CFRunLoopRunSpecific 19 GraphicsServices 0x1842ec088 GSEventRunModal 20 UIKit 0x187c54d90 UIApplicationMain 21 QuikCom 0x1000a1258 main (main.m:14) 22 libdispatch.dylib 0x18297e8b8 (Missing) 致命异常:NSInvalidArgumentException ***-[\uu NSArrayM insertObject:atIndex:]:对象不能为零 线程:致命异常:NSInvalidArgumentException 0 CoreFoundation 0x182ef9900例外预处理 1 libobjc.A.dylib 0x182567f80 objc_异常_抛出 2芯基础0x182de3134 CFSTRINGCONVERTNSTRING编码到编码 3 QuikCom 0x10009e594 \uuuu 27-[ImageSelector loadAssets]\uBlock\uInvoke\u2(ImageSelector.m:65) 4资产库0x18c74ba4c\uuU 62-[ALASSETGROUP\u枚举资产索引:选项:usingBlock:][u block\u invoke147 5 CoreFoundation 0x182df0370[uuuuu 53-[[uuuuu NSArrayM enumerateObjectsWithOptions:usingBlock:][u block\u invoke 6 CoreFoundation 0x182df0268-[\uu nsarray枚举对象选项:使用块:] 7资产库0x18c74b520-[ALASSETGROUP\u枚举资产索引:选项:使用块:] 8 QuikCom 0x10009e4a4 \uuuu 27-[ImageSelector loadAssets]\uBlock\uInvoke(ImageSelector.m:60) 9资产库0x18c74d8e4\uu 68-[AlassetLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:][u block\u invoke\u 3 10 CoreFoundation 0x182df0370[uuuuu 53-[[uuuuu NSArrayM enumerateObjectsWithOptions:usingBlock:][u block\u invoke 11 CoreFoundation 0x182df01e0-[\uu nsarray枚举对象选项:使用块:] 12资产库0x18c74d83c\uu 68-[AlassetLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:][u block\u invoke\u 2 13 libdispatch.dylib 0x18294d630(调度)呼叫(阻塞)和(释放) 14 libdispatch.dylib 0x18294d5f0调度客户端调用 15 libdispatch.dylib 0x182952cf8 _dispatch_main_queue_callback_4CF 16 CoreFoundation 0x182eb0bb0\uuu CFRUNLOOP\u正在为\u主\u调度队列\u提供服务__ 17 CoreFoundation 0x182eaea18\uuuuCFRUnloopRUN 18 CoreFoundation 0x182ddd680 CFRunLoopRunSpecific 19图形服务0x1842ec088 GSEventRunModal 20 UIKit 0x187c54d90 UIApplicationMain 21 QuikCom 0x1000a1258干管(干管m:14) 22 libdispatch.dylib 0x18297e8b8(缺失) 然后检查nil值。获取图像的代码如下所示:

-(void)loadAssets{ __block ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if (group == nil) { return; } [group setAssetsFilter:[ALAssetsFilter allPhotos]]; if ( group != nil && [group numberOfAssets] > 0) { [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) { if (alAsset) { ALAssetRepresentation *representation = [alAsset defaultRepresentation]; UIImage *latestPhotoThumbnail = [UIImage imageWithCGImage:[alAsset thumbnail]]; if (representation != nil &&representation.url != nil && latestPhotoThumbnail != NULL) { [urlArray addObject:representation.url]; [thumbsArr addObject:latestPhotoThumbnail]; representation = nil; latestPhotoThumbnail = nil; } }else{ library = nil; [_collectionView reloadData]; } }]; } [_collectionView reloadData]; } failureBlock: ^(NSError *error) { //NSLog(@"No groups: %@",error); }]; } -(无效)装载资产{ __block AlassetLibrary*library=[[AlassetLibrary alloc]init]; [库枚举组SwithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup*组,布尔*停止){ 如果(组==nil){ 返回; } [group SetAssetFilter:[AlasSetFilter allPhotos]]; 如果(组!=nil&[group numberOfAssets]>0){ [组enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset*ALAsset,NSUNIGER index,BOOL*innerStop){ 如果(设置){ ALAssetRepresentation*表示=[AlasSetDefaultRepresentation]; UIImage*latestPhotoThumbnail=[UIImage imageWithCGImage:[alAsset thumbnail]]; if(representation!=nil&&representation.url!=nil&&latesthotothumbnail!=NULL){ [urlArray addObject:representation.url]; [thumbsArr addObject:最新照片脐带缆]; 代表性=零; 最晚的胸甲=无; } }否则{ 图书馆=无; [_collectionView重新加载数据]; } }]; } [_collectionView重新加载数据]; }故障块:^(N错误*错误){ //NSLog(@“无组:%@”,错误); }]; }
在此之后,应用程序没有崩溃,但集合视图使用没有图像缩略图的空单元格进行渲染。我不知道我做错了什么。

请确保客户端允许从库中获取图像。感谢您的快速回复。是,客户端已授予访问照片的权限。请将AlasSetGroupAll更改为AlasSetGroupPhotoStream,然后再试一次。您是否记录UIImage和URL,以检查它们在做什么?另外,请保存到阵列中,并在最后重新加载数据。我认为客户端手机中的大量照片(超过18k)可能会导致丢失。所以我转向PHPhotoFramework。现在它可以正常工作了。无论如何,谢谢你宝贵的回复。