0

I want to download an Image and save it with Timestamp name.

Below is code that I’ve used :

@IBAction func btnDownload_Clicked(_ sender: UIButton) {
        let timeStamp = String(Date().ticks)
        print("timeStamp : \(timeStamp)")

         UIImageWriteToSavedPhotosAlbum(imgQRCode.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
    }

//MARK: - Add image to Library
    func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
        if let error = error {
            let objAlert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
            objAlert.addAction(UIAlertAction(title: "OK", style: .default))
            present(objAlert, animated: true)
        }
        else {
            let objAlert = UIAlertController(title: "", message: saveQR, preferredStyle: .alert)
            objAlert.addAction(UIAlertAction(title: "OK", style: .default))
            present(objAlert, animated: true)
        }
    }

However, the issue with above code is that how to set Timestamp as name for Image?

I’ve tried this link wherein image is downloaded by not visible in Photos app.

Any quick fix?

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
  • 2
    As per https://stackoverflow.com/a/18447209/4601900 You can not give File name , but you can give metadata – Prashant Tukadiya Sep 06 '17 at 07:11
  • @MikeAlter : Any solution by which image is saved in Photos Album along with custom name? – Jayprakash Dubey Sep 06 '17 at 07:18
  • What you are trying to achieve ? may someone here can help you to find alternative solution :) – Prashant Tukadiya Sep 06 '17 at 07:19
  • @MikeAlter : I want to save the image on press on download button. This image should be visible in Photos app of iPhone with name as Timestamp. – Jayprakash Dubey Sep 06 '17 at 07:20
  • 1
    @JayprakashDubey : It is not possible as `Photo Library` doesn't show the name of any image! So Why you want to do so ? you can set it's metadata, and you can retrieve that metadata also when you pick image from photo library. – Ketan Parmar Sep 06 '17 at 07:32
  • 1
    As it looks like not possible with current SDK, You should create album in photo library and save image into it. may be helpful – Prashant Tukadiya Sep 06 '17 at 07:32

0 Answers0