IOS 获取所有图片工具类

来源:互联网 发布:汽车电脑解码软件 编辑:程序博客网 时间:2024/05/18 00:30
@implementation imageGeter{    }static NSInteger count=0;static ALAssetsLibrary* library;+(void)getAllImage:(void (^)(NSArray *))block{    NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];    library = [[ALAssetsLibrary alloc] init];    NSMutableArray* mutableArray =[[NSMutableArray alloc]init];    void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {        if(result != nil) {                        if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {                                [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];                                                                NSURL *url= (NSURL*) [[result defaultRepresentation]url];                                                                [library assetForURL:url                                          resultBlock:^(ALAsset *asset) {                                                                                     [mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];                                                 if ([mutableArray count]==count)                             {                                  NSArray* imageArray;                                 imageArray=[[NSArray alloc] initWithArray:mutableArray];                                 block(imageArray);                                                              }                                                      }                                         failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];                                                            }                    }            };                NSMutableArray *assetGroups = [[NSMutableArray alloc] init];                void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {                if(group != nil) {                        [group enumerateAssetsUsingBlock:assetEnumerator];                        [assetGroups addObject:group];                        count=[group numberOfAssets];                    }            };                assetGroups = [[NSMutableArray alloc] init];                [library enumerateGroupsWithTypes:ALAssetsGroupAll                                usingBlock:assetGroupEnumerator                              failureBlock:^(NSError *error) {NSLog(@"There is an error");}];}

0 0