iOS ALAssetsLibrary使用ALAssetsGroupAll获取所有图片展示不全

使用 ALAssetsLibrary类的

-(void)enumerateGroupsWithTypes:(ALAssetsGroupType)types usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock方法枚举ALAssetsGroup对象时,types参数为ALAssetsGroupAll,发现并没有获取到相册里的所有图片,半天找不到问题所在,后来发现qq发送图片时,有些图片会先从iCloud同步,然后再发送,于是我猜想那些丢失的图片应该是同步到iCloud,我们本地相册并没有,然后我到手机的照片查看一张模糊的图片,等待图片同步完,再到自己的应用里查看相册,那张同步完的照片就出现了,另外也可以在设置里找到照片把自动同步iCloud关掉,那么本地就全是那些真实存在的图片了,在我们自己的应用里也能看到相册里的所有图片了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
源码SGImagePickerController,1.需要导入这个头文件 #import 2.获取相册分组 - (NSMutableArray *)groups{ if (_groups == nil) { _groups = [NSMutableArray array]; dispatch_async(dispatch_get_main_queue(), ^{ [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { if(group){ [_groups addObject:group]; [self.tableView reloadData]; } } failureBlock:^(NSError *error) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"访问相册失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alertView show]; }]; }); } return _groups; } 3.遍历一组中的资源,包括图片视频等,我们只需要图片 - (void)setGroup:(ALAssetsGroup *)group{ _group = group; [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { if (asset == nil) return ; if (![[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {//不是图片 return; } SGAssetModel *model = [[SGAssetModel alloc] init]; model.thumbnail = [UIImage imageWithCGImage:asset.thumbnail]; model.imageURL = asset.defaultRepresentation.url; [self.assetModels addObject:model]; }]; } 4.遍历可以拿到图片缩略图,原图的URL 图片拍摄地点 拍摄时间等信息,我们只需要缩略图用来展示,原图URL用来获取原图 根据URL获取原图,系统应该是在子线程中的获取原图,注意此处!!! - (void)originalImage:(void (^)(UIImage *))returnImage{ ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init]; [lib assetForURL:self.imageURL resultBlock:^(ALAsset *asset) { ALAssetRepresentation *rep = asset.defaultRepresentation; CGImageRef imageRef = rep.fullResolutionImage; UIImage *image = [UIImage imageWithCGImage:imageRef scale:rep.scale orientation:(UIImageOrientation)rep.orientation]; if (image) { returnImage(image); } } failureBlock:^(NSError *erro
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值