After much research about the best way to save an image to a sqlite db in iOS, i’ve decided to save the filepath of the image in an entity and just reference it when it comes to displaying it as a thumbnail.
I’m using the following code to save the image taken with the camera:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)snagPhoto editingInfo:(NSDictionary *)editingInfo
{
[self.library saveImage:snagPhoto toAlbum:@"Snags" withCompletionBlock:^(NSError *error) {
if (error)
{
NSLog(@"error");
}
}];
[picker dismissModalViewControllerAnimated:NO];
}
All I need to do is get the filepath of ‘snagPhoto’.
The proper method to use on
ALAssetsLibraryiswriteImageToSavedPhotosAlbum:metadata:completionBlock:orwriteImageToSavedPhotosAlbum:orientation:completionBlock:— these will lead to an asset URL that you can later use withassetForURL:resultBlock:failureBlock:to get a reference to the image.