Search code examples
swiftphotos

Get photo that is saved to photo library in swift


So I have a image which I get from my server. I want to save that image locally. I have already considered using Userdefaults or Core Data for this instead, but I want the user to be able to see and view the photos from their photos app. So I have a saved photo which is saved using UIImageWriteToSavedPhotosAlbum. How do I later retrieve that same image in my app? This includes even after the app is closed and relaunched.


Solution

  • Are you using the PHPhotoLibrary framework? If so, you can use PHFetchOptions to fetch the photos that were saved by your application. Enter parameters such as album name to retrieve the photos you have saved.

    If you have the url of the image being stored using UIImageWriteToSavedPhotosAlbum then use that url to retrieve that image using FileManager API.

    Get image from documents directory swift