Member-only story
Download Image and save to Photo (Gallery) in iOS
1 min readNov 8, 2019
UIImageWriteToSavedPhotosAlbum(self.imageView.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)}
Above mention code we have to write for button action where user clicks then they can download the image to Photo.
Before that we have to take permission from user to access for adding image in Photo. so write following key-pair in your info.plist file.
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App require library access.</string>
Here is delegate method for saving photo to image gallery.
//MARK: - Add image to Library@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {if let error = error {// we got back an error!let ac = UIAlertController(title: "Save error", message: error.localizedDescription, preferredStyle: .alert)ac.addAction(UIAlertAction(title: "OK", style: .default))present(ac, animated: true)} else {let ac = UIAlertController(title: "Saved!", message: "Image downloaded successfully...", preferredStyle: .alert)