For the first time I'm trying to save and load a photo, taken by the camera or chosen from the photo gallery. I managed to save pictures, taken by the camera, in the photos album and getting the url of it. I hope the last part is correct. Here is the corresponding code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.selectedImage = info[UIImagePickerControllerOriginalImage];
if (self.userCreatedPhoto == TRUE) {
UIImageWriteToSavedPhotosAlbum(info[UIImagePickerControllerOriginalImage],nil,nil,nil);
}
self.imageURL = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
[self.imageView setImage:self.selectedImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
The photo url gets saved, together with other data, as a NSData object in core data.
article.imageData = [NSData dataWithContentsOfURL:self.imageURL];
Assuming that everything up there is correct, I try to show the saved pictures in a UICollectionView. At this point I fail to load the picture. The following code worked in an earlier development stage of my app where I was saving the whole picture to a NSData in core data and not saving it in the album. Please correct me if I'm wrong and there is a better way, but I thought it would be better this way. So here is the code in the cellForIteamAtIndexPath UICollectionView:
cell.image.image = [UIImage imageWithData:[[_allArticles objectAtIndex:indexPath.row] imageData]];
Using this code, no picture appears at all when using the photo album. I hope someone can help me. Thanks a lot!