使用ALAssetsLibrary从iphone专辑中读取图像会变慢

时间:2016-11-03 13:17:07

标签: ios

使用ALAssetsLibrary从iphone相册中读取图片需要30秒才能加载700张图像。是否还有其他版本的代码使用ALAssetsLibrary?我的代码版本低于

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        NSLog(@"number of assets = %ld",(long)group.numberOfAssets);
        [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
            if(result == nil) {
                return;
            }

            ALAssetRepresentation *representation = [result defaultRepresentation];

            BR_AssetsInfo *info = [[BR_AssetsInfo alloc] init];
            info.thumbnail = [UIImage imageWithCGImage:[result thumbnail]];
            info.originalImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
            info.imageURLString = [[representation url] absoluteString];
            info.isSelected = NO;

            for (BR_AssetsInfo *asset in self.selectedAssetsArray) {
                if ([asset isEqual:info]) {
                    info.isSelected = YES;
                }
            }

            [self.assetsDataArray addObject:info];

            [self.photosCollectionView reloadData];

        }];
    } failureBlock:^(NSError *error) {
        if (error.code == ALAssetsLibraryAccessUserDeniedError) {
            NSLog(@"user denied access, code: %li",(long)error.code);
        }else{
            NSLog(@"Other error code: %li",(long)error.code);
        }
    }];

0 个答案:

没有答案