We want to be able to register a single and periodic task:
registerSingleTask
String id
String taskName
String tag
Enum existingWorkPolicy:
TimeInterval initialDelay
Enum constraints:
- requiresNetworkConnectivity
- requiresExternalPower
Enum backoffPolicy
TimeInterval backoffPolicyDelay
String inputData
registerPeriodicTask
TimeInterval frequency
String id
String taskName
String tag
Enum existingWorkPolicy:
TimeInterval initialDelay
Enum constraints:
- requiresNetworkConnectivity
- requiresExternalPower
Enum backoffPolicy
TimeInterval backoffPolicyDelay
String inputData
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.plist file.
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:
We want to be able to register a single and periodic task:
registerSingleTask
StringidStringtaskNameStringtagEnumexistingWorkPolicy:TimeIntervalinitialDelayEnumconstraints:EnumbackoffPolicyTimeIntervalbackoffPolicyDelayStringinputDataregisterPeriodicTask
TimeIntervalfrequencyStringidStringtaskNameStringtagEnumexistingWorkPolicy:TimeIntervalinitialDelayEnumconstraints:EnumbackoffPolicyTimeIntervalbackoffPolicyDelayStringinputDataWe'll start with supporting only
BGProcessingTaskRequestfor now. Later we can look atBGAppRefreshTaskRequest.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
backoffPolicyandbackoffPolicyDelay.For periodic tasks there is a
frequencyproperty. Meaning that after each succesful 'run' of the task a new task needs to be submitted with an earliestBeginDate calculated using thefrequencythat was passed along.General notes from BGTaskScheduler class docs:
This is something we'll need to clearly mention in our documentation.
From BGTaskScheduler submit(_:) docs:
Useful links: