-
Notifications
You must be signed in to change notification settings - Fork 9
Description
We want to be able to register a single and periodic task:
registerSingleTask
StringidStringtaskNameStringtagEnumexistingWorkPolicy:- keep
- replace
TimeIntervalinitialDelayEnumconstraints:- requiresNetworkConnectivity
- requiresExternalPower
EnumbackoffPolicy- exponential
- linear
TimeIntervalbackoffPolicyDelayStringinputData
registerPeriodicTask
TimeIntervalfrequencyStringidStringtaskNameStringtagEnumexistingWorkPolicy:- keep
- replace
TimeIntervalinitialDelayEnumconstraints:- requiresNetworkConnectivity
- requiresExternalPower
EnumbackoffPolicy- exponential
- linear
TimeIntervalbackoffPolicyDelayStringinputData
We'll start with supporting only BGProcessingTaskRequest for now. Later we can look at BGAppRefreshTaskRequest.
Internally we'll need to keep a complete state of the different tasks.
We need to keep a reference to the tasks in order to know how to behave when a new registration comes in with the same id. Depending on the existingWorkPolicy, the previously registered task needs to be left alone or resubmitted. We also want to be able to cancel all requests with a certain tag. If a task fails it needs to be resubmitted based on the backoffPolicy and backoffPolicyDelay.
For periodic tasks there is a frequency property. Meaning that after each succesful 'run' of the task a new task needs to be submitted with an earliestBeginDate calculated using the frequency that was passed along.
General notes from BGTaskScheduler class docs:
The system runs only tasks registered with identifiers on a whitelist of task identifiers. To add the whitelist, add the identifiers to the
Info.plistfile.
This is something we'll need to clearly mention in our documentation.
From BGTaskScheduler submit(_:) docs:
Submitting a task request for an unexecuted task that’s already in the queue replaces the previous task request.
There can be a total of 1 refresh task and 10 processing tasks scheduled at any time. Trying to schedule more tasks returns
BGTaskScheduler.Error.Code.tooManyPendingTaskRequests.
Useful links: