My app crashes every time when I try to save image using photo framework.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMedi
Here is an example of code how you can write/save image to Photo Library using UIImageWriteToSavedPhotosAlbum function:
- (void)saveImage:(UIImage *)image {
UIImageWriteToSavedPhotosAlbum(self.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
{
if (!error) {
// saved successfully
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHAsset *asset = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions].firstObject;
if (asset != nil) {
// here you can use asset of your image
}
} else {
NSLog(@"save image error: %@", error);
}
}
Don't forget to add into your Info.plist a key-value pair Privacy - Camera Usage Description with description of usage.