All the nuances of when and whether a background task runs aside, does launching the app cancel the currently scheduled refresh task? As an example, consider the following case:
- 8AM - user launches app. This launch schedules a background refresh for 12 hours later, at 8PM
- 12PM (noon) - user launches the app, views some content, then exits the app.
Does the scheduled refresh for 8PM still exist, or does the launch at noon invalidate that task, since the refresh could conceivably be handled during that noon launch?
Hopefully this is articulated clearly enough, but I'm trying to understand the specifics of background refresh behavior, since I don't want to run that refresh every time the app is opened. However, if opening the app invalidates scheduled refreshes, I will need to include logic that will reschedule the refresh accordingly.
First I would like to clarify something. There is no such thing as scheduling a background task at a certain time. You usually schedule your background task, and the system will, at its discretion, dynamically determine when it is appropriate to run your task (making sure it is not run before the time you specified).
Launching the app sometime during the day may, just like many other activities the user will have on their device, influence the next time the system find it appropriate to run your task. But the ifs and whens of that is not deterministic as far as you are concerned as a developer.
Other than that, the tasks will not be canceled. you can always check if there are any pending tasks by using the getPendingTaskRequests(completionHandler:) function.
You also have the option to cancel(taskRequestWithIdentifier:) and then create a new one when your app is launched in the middle of the day and you think you wouldn't need to have a background refresh too soon after.
Argun Tekant / DTS Engineer / Core Technologies