registerPeriodicTask method
- String uniqueName,
- String taskName, {
- Duration? frequency,
- Duration? flexInterval,
- Map<
String, dynamic> ? inputData, - Duration? initialDelay,
- Constraints? constraints,
- ExistingPeriodicWorkPolicy? existingWorkPolicy,
- BackoffPolicy? backoffPolicy,
- Duration? backoffPolicyDelay,
- String? tag,
Schedules a periodic task that will run every provided frequency.
On iOS it is not guaranteed when or how often it will run, iOS will schedule it as per user's App usage pattern, iOS might terminate the task or throttle it's frequency if it takes more than 30 seconds.
A uniqueName is required so only one task can be registered.
The taskName is the value that will be returned in the BackgroundTaskHandler, ignored on iOS where you should use uniqueName.
a frequency is not required and will be defaulted to 15 minutes if not provided.
a frequency has a minimum of 15 min. Android will automatically change your frequency to 15 min if you have configured a lower frequency.
the flexInterval If the nature of the work is time-sensitive, you can configure the PeriodicWorkRequest to run in a flexible period at each interval.
The inputData is the input data for task. Valid value types are: int, bool, double, String and their list
Unlike Android, you cannot set frequency for iOS here rather you have to set in AppDelegate.swift while registering the task.
The inputData is the input data for task. Valid value types are: int, bool, double, String and their list. It is not supported on iOS.
For iOS see Apple docs: iOS 13+ Using background tasks to update your app
Implementation
Future<void> registerPeriodicTask(
String uniqueName,
String taskName, {
Duration? frequency,
Duration? flexInterval,
Map<String, dynamic>? inputData,
Duration? initialDelay,
Constraints? constraints,
ExistingPeriodicWorkPolicy? existingWorkPolicy,
BackoffPolicy? backoffPolicy,
Duration? backoffPolicyDelay,
String? tag,
}) async {
return _platform.registerPeriodicTask(
uniqueName,
taskName,
frequency: frequency,
flexInterval: flexInterval,
inputData: inputData,
initialDelay: initialDelay,
constraints: constraints,
existingWorkPolicy: existingWorkPolicy,
backoffPolicy: backoffPolicy,
backoffPolicyDelay: backoffPolicyDelay,
tag: tag,
);
}