I want to access all photos from camera roll my code is working fine if i have few images in camera roll then app is working fine but if i have more than 1000 photos then app crashes here is my code
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
NSMutableArray *arrImages=[[NSMutableArray alloc]init];
NSString *albumName = [group valueForProperty:ALAssetsGroupPropertyName];
if (albumName !=nil) {
[arrGroupsNames addObject:albumName];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
UIImage *img=[self imageForAsset:asset];
[arrImages addObject:img];
}
}
];
[arrGroups addObject:arrImages];
}
[self.tableVieww reloadData];
}
failureBlock:^(NSError *error)
{
// User did not allow access to library
NSLog(@"error");
}
];
and here is the function which return image from ALAsset
-(UIImage*) imageForAsset:(ALAsset*) aAsset{
ALAssetRepresentation *rep;
rep = [aAsset defaultRepresentation];
return [UIImage imageWithCGImage:[rep fullResolutionImage]];
}
Aucun commentaire:
Enregistrer un commentaire