Copy image from document directory to photos library in Swift iOS

683 Views Asked by At

I am having a string array of names of images stored in the document directory of the application. I want to Copy images from the document directory of the application to the PHOTOS LIBRARY OF DEVICE.

1

There are 1 best solutions below

0
Zankynn On BEST ANSWER

Swift 4

I will tell you the steps to save a photo from Document] -> [Photos Library] in the easiest way that is using UIImageWriteToSavedPhotosAlbum() function of UIKit

Step 1:

Step 2:

  • Get the [image data] you want to copy with Data(contentsOf: URL)
  • You can learn how to get the [Url] of the file in the [Document], do a search because this job has a lot of articles and is also very easy to do. Dont worried

Step 3:

  • Create a [UIImage] from the [Data] you got above

Step 4:

  • Pass the [UIImage] present in step 3 to the first parameter of UIImageWriteToSavedPhotosAlbum(). All remaining parameters can be set to nil.