0

Just started a few days ago and trying to learn. I have an image within my UIImageView, how do I save this to my gallery? I have created a button with an IBAction on it

Is it related to .pngData() ?

Thanks

Roshan
  • 712
  • 4
  • 17
chuckbass
  • 95
  • 7
  • 1
    Possible duplicate of [How to save picture to iPhone photo library?](https://stackoverflow.com/questions/178915/how-to-save-picture-to-iphone-photo-library) – Bhavesh.iosDev Nov 25 '18 at 13:39

1 Answers1

1
@IBAction func nameOfFunctionToSave(_ sender: AnyObject) {
  UIImageWriteToSavedPhotosAlbum(imageTake.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}

extension photoPickerController :  UIImagePickerControllerDelegate  {
    func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
         if let error = error {
          // in case we get an error
           let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
           alert.addAction(UIAlertAction(title: "OK", style: .default))
           present(alert, animated: true)
         } else {
          // in case of success
           let alert = UIAlertController(title: "Saved!", message: "Image saved successfully in your library", preferredStyle: .alert)
           alert.addAction(UIAlertAction(title: "OK", style: .default))
           present(alert, animated: true)
         }
}
Braham Youssef
  • 479
  • 6
  • 6