0

I am using a very simple code to download an image from url

let url = URL(string: "https://images.unsplash.com/photo-1577771488438-6307361e4023?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80")!

let data1 = try? Data(contentsOf: url)
let image = UIImage(data: data1!);
print("want to show download progress here") // here want to show download progress.
UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)

My only problem is that i am unable to show the download progress(just want to print the progress and not show in the UI)

P.S:- I am creating a plugin for flutter which uses native code to run. its easier for me to create the plugin on android(since I am from android background).

  • 2
    Note, you should not download synchronously using Data(contentsOf:) in general and specifically not when you want to show the progress or otherwise let your app continue to work while downloading – Joakim Danielson Jul 07 '21 at 07:19
  • point noted. i am changing the code with URLSessionDataTask. thanks – Arpit todewale Jul 07 '21 at 07:40

0 Answers0