I was using ELCImagePicker and was facing same problem while importing multiple photos at a time from photos library using asselts. We can not reduce time taken to import but crash issue will be resolved.
for (int j=0; j<[assetArray count]; j++)
{
@autoreleasepool // This is compiler level feature so will only work on xcode 4.1 or above
{
ALAsset *assest = [assetArray objectAtIndex:j];
CGImageRef imageRef = assest.defaultRepresentation.fullResolutionImage;
UIImage *image = [UIImage imageWithCGImage:imageRef];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:documentsPath atomically:YES];
}
}
If possible try to store only AssetURL in assetArray instead of whole ALAsset object and create ALAsset at a time from url so may be it helps to reduce memory consumption. In such case you will need to use blocks as
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [[myasset defaultRepresentation] fullResolutionImage];
if (iref) //You have image so use it
{
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:imageURL resultBlock:resultblock failureBlock:failureblock];