Given I have a standard background URLSession and URLSessionDownloadTask, as below (I deliberately simplified the code for the sake of the example):
It seems that enabling/disabling Background App Refresh (Settings => General => Background App Refresh) changes how URLSession and its delegate behave.
When background app refresh is on, the OS wakes up my app in background and call the delegate methods as described in Apples documentation, which allows me for example to move my downloaded file in the Photo library.
When background app refresh is off, the delegate methods are never called while the app is in background. They are however called when the app the user puts the app back in foreground.
The code running in both scenarios is the same, it implements URLSessionDownloadDelegate in a manager and application(_:handleEventsForBackgroundURLSession:completionHandler:) in the app delegate.
I can't find any official documentation from Apple stating this is true. Background app refresh is only supposed to have an effect on the Background App Refresh API (which allows you to use background fetch and background processing).
Has anyone been able to download a file in background and move it in background with Background App Refresh turned off?
Code Block let sessionConfig = URLSessionConfiguration.background(withIdentifier: "mySessionID") sessionConfig.isDiscretionary = false sessionConfig.sessionSendsLaunchEvents = true self.urlSession = URLSession(configuration: sessionConfig, delegate: self, delegateQueue: nil) let task = urlSession.downloadTask(with: url) task.resume()
It seems that enabling/disabling Background App Refresh (Settings => General => Background App Refresh) changes how URLSession and its delegate behave.
When background app refresh is on, the OS wakes up my app in background and call the delegate methods as described in Apples documentation, which allows me for example to move my downloaded file in the Photo library.
When background app refresh is off, the delegate methods are never called while the app is in background. They are however called when the app the user puts the app back in foreground.
The code running in both scenarios is the same, it implements URLSessionDownloadDelegate in a manager and application(_:handleEventsForBackgroundURLSession:completionHandler:) in the app delegate.
I can't find any official documentation from Apple stating this is true. Background app refresh is only supposed to have an effect on the Background App Refresh API (which allows you to use background fetch and background processing).
Has anyone been able to download a file in background and move it in background with Background App Refresh turned off?
So thanks to this thread, I finally found an answer. See Quinn's response below :
iOS 13 introduces new behaviour (r. 47718087) whereby, if the user has turned Background App Refresh off in Settings — either globally or for your app, assuming it has this setting — your app won’t be resumed (or relaunched) when the tasks complete in an NSURLSession background session. That is, your session will behave as if sessionSendsLaunchEvents were set to false.