I'm getting a problem highlighted in red above. When I take a picture and press use photo, it won't let me save the photo I took to the photo album on my iPad. I have looked at other ways but me being a beginner to iOS development, I'm unsure of how to fix this problem. I sometimes get a sigabrt error too.
Have you provided the completion Selector?
...
UIImageWriteToSavedPhotosAlbum(imageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
...
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
}
}
You can use this;
@IBAction func downloadButton(_ sender: Any) {
let imageRepresentation = UIImagePNGRepresentation(photoView.image!)
let imageData = UIImage(data: imageRepresentation!)
UIImageWriteToSavedPhotosAlbum(imageData!, nil, nil, nil)
let alert = UIAlertController(title: "Completed", message: "Image has been saved!", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}