需导入AssetsLibrary和OpenAL.framework
-(IBAction)getAllPictures:(id)sender
{NSArray *imageArray=[[NSArray alloc] init];
NSMutableArray *arr =[[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {//获取所有group
if(group)
{
count = group.numberOfAssets;
}
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {//从group里面
NSString* assetType = [result valueForProperty:ALAssetPropertyType];
if ([assetType isEqualToString:ALAssetTypePhoto]) //获取类型是photo的
{
NSURL *url= (NSURL*) [[result defaultRepresentation]url];[library assetForURL:url resultBlock:^(ALAsset *asset) {
[arr addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
if(arr.count == count)
{
imageArray=[[NSArray alloc] initWithArray:arr];
[self allPhotosCollected:imageArray];
}
} failureBlock:^(NSError *error){
NSLog(@"operation was not successfull!");
}];
}
}];
} failureBlock:^(NSError *error) {
NSLog(@"Enumerate the asset groups failed.");
}];
}
-(void)allPhotosCollected:(NSArray*)imgArray
{
NSLog(@"all pictures are %@",imgArray);
}