I have tested that BGAppRefreshTaskRequest works as expected when app is still in the memory, but when I killed the app this seems not being triggered. So my question will the BGTask will ever run if the app is killed by user.
I checked the documentation for BGTaskScheduler and it says
Background tasks give your app a way to run code while the app is suspended.
Which means that this will not schedule any task if the app is killed.
But on the other hand we have Handle background events
Which tells that
If your app isn’t running when an event arrives, the system launches the app and moves it directly to the background, following this sequence:
- The system launches the app and follows the initialization sequence described in About the app launch sequence.
- UIKit calls the app delegate’s applicationDidEnterBackground(_:) method.
- UIKit delivers the event that caused the launch.
- The app’s snapshot is taken.
- The app may be suspended again.
So I'm bit confused. Will background refresh gets triggered when app is killed.
The exact details for this have changed over time but, in general, you should not expect your app to run in the background if it has been explicitly killed by the user by swiping up in the multitasking UI. The system interprets that as a strong signal that they user don’t want your app running in the background. It won’t run the app in the background again until the user manually launches the app.
Many background execution APIs will either resume or relaunch your app in the background. If you want to test the relaunch case, I have some hints and tips about that in Testing Background Session Code (which is about NSURLSession
but the same techniques apply here as well).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"