Updated 16 February 2022


Hello, In this blog we are going to learn about how to save images in the photo library on an IOS device. UIImageWriteToSavedPhotosAlbum API is used to save your project image in the photo library of the iOS device.

UIImageWriteToSavedPhotosAlbum is a public function of the UIKit framework. It is used to save the image in the iPhone Photo Library. This function takes 4 arguments. The first one is the Image that is required. The second one is the completionTarget which tells where the selector method is implemented. The third one is the completionSelector which gets the name of selector method that’s called when the image saving processing gets completed. The final one is contextInfo which is UnsafeMutableRawPointer.

UIImageWriteToSavedPhotosAlbum Example

In the above example, you can see when the saveImagetoDocumentDirectory is called it takes the first visible image from the UI and same that image in the photo library. Once this process is completed the didFinishSavingWithError method is called. If some error occurs while saving the image then this error parameter contains that error. Therefore, in the code first, we have checked if the error parameter contains any value or not. And if it contains any value then we use UIAlertController it to show an error to the end-user.

Thank you for reading this article. After that, if you want to read more articles regarding iOS Development click here or if you want to read more about UIImageWriteToSavedPhotosAlbum function click here.

. . .
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home