I have created a class to download file using URLSession
.
I noticed a weird behavior that when device in debug mode, it is downloading files. But if I remove device and run app manually, downloading is not working at all. Sometimes re-attaching device starts the download.
This is how I am creating URLSession :
private lazy var urlSession: URLSession = {
let config = URLSessionConfiguration.background(withIdentifier: "org.company.id")
config.isDiscretionary = true
config.sessionSendsLaunchEvents = true
config.allowsCellularAccess = true
return URLSession(configuration: config, delegate: self, delegateQueue: nil)
}()
And here is my request download function :
func requestDownload(urlString: String){
guard let url = URL(string: urlString) else {return}
downloadTask = urlSession.downloadTask(with: url)
downloadTask.taskDescription = urlString
downloadTask.resume()
}
Here is a link to that file downloader class : https://github.com/skdevil/PrakrstaFileDownloader
Any idea how to fix it ?