I am developing an iPad app in which I let the user create an object. Also I allow him/her to add 10 pictures to this object. They can select these pictures from their camera roll or take a new one (if the iPad has a camera).
My question now is what would be the best way to store these pictures? In my opinion the best way would be to make use of the UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:finishedSavingWithError:contextInfo:), nil);
method. This way I can always store (or use) the images in the iPad's photo album. But in this case I'd need to be able to store something in the database to be able to retrieve the image again later on. So... How do I obtain a URL to the file's path, inside the finishedSavingWithError:contextInfo:
method, to store in the database?
Another way to achieve my goal would be to save them to a private folder as:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = image;
[ImageManager saveImage:image atIndex:0];
}
}
And my saveImage
method does the following:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", index]];
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
Or should I store the images as a BLOB in the sqlite database?
Personally I think these last 2 possibilities blow because basically you're storing everything twice. If you select an image from your gallery, it'll be stored locally (your gallery) PLUS in the database or in an application sub-directory. Which is a waste of space.
What is the best way to do this, performance wise?
And also, if I store them in a directory, can the user access this directory and remove them?
Thanks for sharing your wisdom!