我想获取相册里的所有图片进入一个NSDictionary里面
来源:互联网 发布:和文化精髓知乎 编辑:程序博客网 时间:2024/06/04 20:58
NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
// NSMutableArray* data = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
{
NSString* type = [result valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypePhoto])
{
ALAssetRepresentation* represent = result.defaultRepresentation;
CGImageRef imgRef = [represent fullResolutionImage];
UIImage* image = [UIImage imageWithCGImage:imgRef scale:represent.scale orientation:(UIImageOrientation)represent.orientation];
NSDictionary* dictionaryURL = [result valueForProperty:ALAssetPropertyURLs];
NSString* url;
for (NSString* str in dictionaryURL)
{
url = [dictionaryURL objectForKey:str];
}
[dictionary setObject:image forKey:url];
}
}];
}
failureBlock:^(NSError *error)
{
NSLog(@"erro!!!");
}];
以上是我写的代码,运行之后发现没有办法放进去,调试之后发现应该是函数中的block运行的时候已经是所有函数运行之后了。
只有在所有程序运行完了之后才运行block所以我就没有办法处理NSDictionary里面的照片了,求大神告知解决方法。
有没有方法可以提前调用那个block?
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
// NSMutableArray* data = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
{
NSString* type = [result valueForProperty:ALAssetPropertyType];
if ([type isEqualToString:ALAssetTypePhoto])
{
ALAssetRepresentation* represent = result.defaultRepresentation;
CGImageRef imgRef = [represent fullResolutionImage];
UIImage* image = [UIImage imageWithCGImage:imgRef scale:represent.scale orientation:(UIImageOrientation)represent.orientation];
NSDictionary* dictionaryURL = [result valueForProperty:ALAssetPropertyURLs];
NSString* url;
for (NSString* str in dictionaryURL)
{
url = [dictionaryURL objectForKey:str];
}
[dictionary setObject:image forKey:url];
}
}];
}
failureBlock:^(NSError *error)
{
NSLog(@"erro!!!");
}];
以上是我写的代码,运行之后发现没有办法放进去,调试之后发现应该是函数中的block运行的时候已经是所有函数运行之后了。
只有在所有程序运行完了之后才运行block所以我就没有办法处理NSDictionary里面的照片了,求大神告知解决方法。
有没有方法可以提前调用那个block?
0 0
- 我想获取相册里的所有图片进入一个NSDictionary里面
- 获取相册里的图片 名称
- iOS 获取本地相册的所有图片
- Android获取系统相册里的全部图片
- 从android相册获取所有图片的路径
- 获取本地所有图片显示并可多选的本地相册
- iOS8下获取相册所有图片
- iOS8下获取相册所有图片
- iOS获取相册中所有图片
- iOS8下获取相册所有图片
- Android获取系统相册所有图片
- Android实现获取手机里面的所有图片
- Android实现获取手机里面的所有图片
- 获取IPhone相册中图片的方法(包括获取所有图片)
- 获取IPhone相册中图片的方法(包括获取所有图片)
- 获取IPhone相册中图片的方法(包括获取所有图片)
- 获取IPhone相册中图片的方法(包括获取所有图片)
- 获取IPhone相册中图片的方法(包括获取所有图片)
- 简述对CSS的盒子模型理解?
- 远程桌面rdp工具
- Android开发之单行文本自动播放效果
- java学习笔记之---Struts2基础
- Android 封装Fragment-BaseLazyFragment(懒加载)
- 我想获取相册里的所有图片进入一个NSDictionary里面
- JVM之-GC垃圾收集器(一)
- gulp教程之gulp-imagemin压缩图片
- 解决Tomcat 不定时报OutOfMemoryError: PermGen space
- oracle 递归查询学习
- WriteConsoleOutput(二)
- Java中的多态调用问题,下面代码输出是什么?
- python[glob+rmtree来删除目录和子目录及其下所有文件]
- 求帮忙 写一个计算公式