I download files to the device
And I am displaying the loading process in the progressbar
I do it like this

 func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) { loadedURLsCount += 1 let progress = ((Float(totalBytesWritten) / Float(totalBytesExpectedToWrite) + Float(loadedURLsCount)) / Float(self.urlsCount))*2 DispatchQueue.main.async { self.progressBar.setProgress(progress, animated: true) if (self.progressBar.progress = 1.0){ UserDefaults.standard.set("true", forKey: "downloaded_all") } else{ print(self.loadedURLsCount) self.per_cents.text = "\(Int(progress*100))%" } } } 

loadedURLsCount is what has already been downloaded
urlsCount is the amount you need to download
When I run the application on the simulator, everything works fine, the indicator shows everything correctly and reaches 100%
And when I launch the application on the iphone, the download goes further than 100% and ends reaching about 500%
Why it happens?
I checked many times on different devices and on different simulators.
And always on the simulator everything works correctly.
How to solve this problem?

    0