博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
得到相册里面的全部图片
阅读量:5288 次
发布时间:2019-06-14

本文共 2072 字,大约阅读时间需要 6 分钟。

原文地址:
作者:

#import<AssetsLibrary/AssetsLibrary.h>

 

 

-(void)getImgs{

    

   dispatch_async(dispatch_get_main_queue(), ^{

       NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc] init];

        

        

       ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){

            NSLog(@"相册访问失败 =%@", [myerrorlocalizedDescription]);

            if ([myerror.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {

                  NSLog(@"无法访问相册.请在'设置->定位服务'设置为打开状态.");

            }else{

                NSLog(@"相册访问失败.");

            }

        };

        

        ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result,NSUIntegerindex, BOOL *stop){

            if (result!=NULL) {

        

                if ([[resultvalueForProperty:ALAssetPropertyType]isEqualToString:ALAssetTypePhoto]) {

                    

                    NSString *urlstr=[NSStringstringWithFormat:@"%@",result.defaultRepresentation.url];//图片的url

 

                    

                  [self._dataArray addObject:urlstr];

                }

            }

           

        };

       ALAssetsLibraryGroupsEnumerationResultsBlock

        libraryGroupsEnumeration = ^(ALAssetsGroup* group,BOOL* stop){

            

            if (group == nil) 

            {

                

            }

            

            if (group!=nil) {

                NSString *g=[NSString stringWithFormat:@"%@",group];//获取相簿的组

               NSLog(@"gg:%@",g);//gg:ALAssetsGroup - Name:Camera Roll, Type:Saved Photos, Assets count:71

 

                NSString *g1=[g substringFromIndex:16 ] ;

                NSArray *arr=[[NSArray alloc] init];

                arr=[g1componentsSeparatedByString:@","];

                NSString *g2=[[arr objectAtIndex:0]substringFromIndex:5];

                if ([g2 isEqualToString:@"Camera Roll"]) {

                    g2=@"相机胶卷";

                }

                NSString *groupName=g2;//组的name

                

                [groupenumerateAssetsUsingBlock:groupEnumerAtion];

            }

            

        };

        

       ALAssetsLibrary* library = [[ALAssetsLibraryalloc] init];

        [libraryenumerateGroupsWithTypes:ALAssetsGroupAll

                              usingBlock:libraryGroupsEnumeration 

                            failureBlock:failureblock];

        [library release];      

 

        [pool release];

    });  

    

}

 

//------------------------根据图片的url反取图片-----

 

 ALAssetsLibrary *assetLibrary=[[ALAssetsLibraryalloc] init]; 

NSURL *url=[NSURLURLWithString:urlStr];

[assetLibrary assetForURL:url resultBlock:^(ALAsset *asset)  {

                UIImage *image=[UIImage imageWithCGImage:asset.thumbnail];

                cellImageView.image=image;

           

                }failureBlock:^(NSError *error) {

                    NSLog(@"error=%@",error);

            }

             ];

//---------------------

 

转载于:https://www.cnblogs.com/sgdkg/p/3167278.html

你可能感兴趣的文章
php 调用java类
查看>>
帝国cms7.0忘记后台管理账户用户名密码
查看>>
hdu 2255 二分图最大权匹配 *
查看>>
bzoj 1415 期望+记忆化搜索 ****
查看>>
Lesson_fun
查看>>
黑客语(Leet)
查看>>
【读书笔记】【CLR via C#】【第一章】The CLR’s Execution Model
查看>>
Flex AIR Mobile应用性能解决方案
查看>>
从零学React Native之08Image组件
查看>>
Python学习 - 函数
查看>>
单个索引与复合索引
查看>>
install.php
查看>>
csv导出
查看>>
【软件工程】重构-改善既有代码的设计
查看>>
高可用Kubernetes集群-12. 部署kubernetes-ingress
查看>>
复利计算(结对编程)评论
查看>>
博客园 Mac客户端 2.0 正式发布!
查看>>
Java---容器基础总结
查看>>
清除Windows的DNS缓存
查看>>
发出HTTP请求并获得HTTP响应
查看>>