0

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

致命异常:NSInvalidArgumentException
*** -[__NSArrayM insertObject:atIndex:]: 对象不能为 nil

线程:致命异常:NSInvalidArgumentException
    0 核心基础 0x182ef9900 __exceptionPreprocess
    1 libobjc.A.dylib 0x182567f80 objc_exception_throw
    2 核心基础 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 核心基础 0x182eb0bb0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
    17 核心基础 0x182eaea18 __CFRunLoopRun
    18 核心基础 0x182ddd680 CFRunLoopRunSpecific
    19 图形服务 0x1842ec088 GSEventRunModal
    20 UIKit 0x187c54d90 UIApplicationMain
    21 QuikCom 0x1000a1258 主 (main.m:14)
    22 libdispatch.dylib 0x18297e8b8(缺失)

然后检查 nil 值。获取图片的代码如下:

-(无效)加载资产{

    __block ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [库 enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

        如果(组==无){
            返回;
        }

        [组 setAssetsFilter:[ALAssetsFilter allPhotos]];

        if ( group != nil && [group numberOfAssets] > 0) {
            [组 enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {

                如果(资产){

                    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];
                        表示=无;
                        最新照片缩略图 = 无;
                    }

                }别的{
                    图书馆=无;
                    [_collectionView reloadData];
                }
            }];
        }

        [_collectionView reloadData];

    } failureBlock: ^(NSError *error) {

        //NSLog(@"无组:%@",error);
    }];
}

之后,应用程序没有崩溃,但集合视图正在呈现没有图像缩略图的空单元格。我不知道我做错了什么。

4

0 回答 0