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?