0

I am trying to save an image to the user's photo library using PHPhotoLibrary and set the image file name at the time of saving the code below. This is working the first time, but if I then try to save the same image again with a different file name, it saves with the same file name as before.

Is there something I need to add to let the system know to save a new version of the image with a new file name?

PHPhotoLibrary.shared().performChanges ({
    let assetType:PHAssetResourceType = .photo
    let request:PHAssetCreationRequest = .forAsset()
    let createOptions:PHAssetResourceCreationOptions = PHAssetResourceCreationOptions()
    createOptions.originalFilename = "\(fileName)"
    request.addResource(with: assetType, data: image.jpegData(compressionQuality: 1)!, options: createOptions)
}, completionHandler: { success, error in
    if success == true && error == nil {
        print("Success saving image")
    } else {
        print("Error saving image: \(error!.localizedDescription)")
    }
})

Save the new image with the required file name

burnsi
  • 6,194
  • 13
  • 17
  • 27

0 Answers0