xy371661665 2015-02-02 15:06 采纳率: 33.3%
浏览 1759
已采纳

我想从手机相册中获取照片储存到NSDictionary中,下面是我写的代码

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!!!");
}];
运行之后没有办法储存到NSDictionary中,调试之后发现所有的block都是在程序后面运行的,所以我无法处理图片。有没有方法可以提前调用这个里面的block或者其他的方法?求大神告知

  • 写回答

1条回答 默认 最新

  • 绿箭绿 2015-02-03 11:16
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因