I'm using URLSession and downloadTask to download a file in the foreground. The download is much slower than expected. Other posts I found address the issue for background tasks.
let config = URLSessionConfiguration.default
config.httpMaximumConnectionsPerHost = 20
let session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
let request = URLRequest(url: url)
let completion: ((URL?, Error?) -> Void) = { (tempLocalUrl, error) in
print("Download over")
}
value.completion = completion
value.task = self.session.downloadTask(with: request)
I'm observing a network usage of ~150kb/s while a speed test on my device reports a connection of 5MB/s
=== Edit
I can confirm that coding a multipart download (which is a bit of a pain to do) speeds up things by a lot.
If that helps anyone, here is my code to speed up the download. It splits the file download in a number of file parts downloads, which uses the available bandwidth more efficiently. It still feels wrong to have to do that...
The final usage is like:
and here's the code: