I have a syncing functionality, where a series of downloads happens in the background.
For that, I create a URLSession instance with background configuration as below:
let config = URLSessionConfiguration.background(withIdentifier: "BackgroundSessionDL")
config.httpMaximumConnectionsPerHost = 20
self.session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
Each of the download tasks (which may be in a number of few hundreds) is added as follows:
var request = URLRequest(url: url)
request.addValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
let downloadTask = self.session.downloadTask(with: request)
downloadTask.resume()
This code works perfectly on iOS 12 or earlier - the download continues even in the background for the tasks already added. But, for iOS 13, causes issue as follows:
- As soon as app goes to background, downloading stops.
- If any download task is in progress and app is put to background, no callaback related logs are observed even after app is again brought to foreground.
I tried to search whether any new classes/framework introduced by Apple for background task download on iOS 13, but did not find anything on this. Also, class used in earlier versions, for representation of a background download task, is still NOT deprecated in iOS 13 and is the only result when searched for background download on iOS 13. Similarly, background configuration used for the HTTP session, is still NOT deprecated. So, I believe the current background download implementation is the one recommended by Apple. (As per my understanding, "BGTaskScheduler" is not intended for this, please correct me if wrong).
So, is this due to any newly introduced bug in iOS 13? OR any change in this implementation, specific to iOS 13, is expected by Apple?
Edit:
I have already added the handleEventsForBackgroundURLSession
callback. Found that the respective logs are not printed and app size does not increase in Settings on iOS 13. So, it appears that download does not continue in the background and it is not related to download related callbacks not getting invoked.