I’m using ELCImagePickerController so I can select multiple photos and import them. It works fine when I select a few photos, but if I select over around 25, I get a crash. Here’s the code that runs after I hit done selecting photos:
-(void)selectedAssets:(NSArray*)_assets {
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
int count=0;
for(ALAsset *asset in _assets) {
NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
[workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"];
UIImage *image=[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
[workingDictionary setObject:image forKey:@"UIImagePickerControllerOriginalImage"];
[workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];
NSLog(@"%i", count);
count++;
[returnArray addObject:workingDictionary];
}
[self popToRootViewControllerAnimated:NO];
[[self parentViewController] dismissModalViewControllerAnimated:YES];
if([delegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
[delegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:[NSArray arrayWithArray:returnArray]];
}
}
I selected 80 photos, and the NSLog statement displays up to 45, but then it just crashes with no message, just (gdb).
The images I’m selecting are iPhone 4 images captured with the rear camera. I’ve tried resizing the images too upon importing, but even then the app still crashes. Any ideas of what could be the problem?
I’m going to put that as an answer if you don’t mind.
There are few solutions to this problem. First you might want to restrict user from selecting more than something like 5 photos. Second you might want to resize your images and make them really small before putting them into an array or something. Or if you need them all in the original size, you can copy them upon selection to your ~/tmp directory and instead store the links to them in your NSArray, so that you could load them dynamically from disk instead of keeping them all in memory.
Sorry if it doesn’t helps since I don’t really know your ultimate goal in using such amount of images at the same time.