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,
- ForegroundServiceConfig? foregroundServiceConfig,
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.
On iOS the handler receives the BGTaskScheduler identifier (the uniqueName),
because the identifier is what you register in Info.plist.
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
On iOS, frequency is not used: the scheduling hint comes from
initialDelay (mapped to BGTaskScheduler's earliestBeginDate). The
launch handler is registered automatically by the plugin, so no
AppDelegate.swift code is required.
The inputData is the input data for task. Valid value types are: int, bool, double, String and their list.
For iOS see Apple docs: iOS 13+ Using background tasks to update your app
foregroundServiceConfig: when provided (Android only), the worker runs
as an Android foreground service for the whole duration of the task,
showing a persistent notification. See ForegroundServiceConfig.
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,
ForegroundServiceConfig? foregroundServiceConfig,
}) async {
return _platform.registerPeriodicTask(
uniqueName,
taskName,
frequency: frequency,
flexInterval: flexInterval,
inputData: inputData,
initialDelay: initialDelay,
constraints: constraints,
existingWorkPolicy: existingWorkPolicy,
backoffPolicy: backoffPolicy,
backoffPolicyDelay: backoffPolicyDelay,
tag: tag,
foregroundServiceConfig: foregroundServiceConfig,
);
}