simple_work_manager 0.0.5+5 copy "simple_work_manager: ^0.0.5+5" to clipboard
simple_work_manager: ^0.0.5+5 copied to clipboard

outdated

Simple Work Manager for Android and iOS.

simple_work_manager #

Simple Work Manager for Android and iOS.

Abstracts #

Simple Work Manager is mapped to Android Work Manager and iOS BGTaskScheduler.

Getting Started #

pubspec.yaml #

Add "simple_work_manager:" into pubspec.yaml.

dependencies:
  simple_work_manager:

iOS #

1. Permitted background task scheduler identifier in info.plist in Xcode Set PermittedBackgroundTaskSchedulerIdentifier as unique string like <[com].[domain].background.process>.
2. Background modes in Xcode
Check Background processing.

Import #

import 'package:simple_work_manager/simple_work_manager.dart';

Preparing callback function #

@pragma("vm:entry-point")
void callbackDispatcher() {
    // execute background jobs here.
    // Jobs can include async function call.
}

Defines callback function as top level function. The callback function is called in repetition.

Instantiate SimpleWorkManager() #

  SimpleWorkManager _simpleWorkManagerPlugin = 
        SimpleWorkManager(callbackFunction: callbackDispatcher);

Specifies callbackFunction defined above. Specifies callbackFunctionIdentifier as arbitrarily non-empty string, typically same as callbackFunction name.

Schedule #

_simpleWorkManagerPlugin.schedule(
    AndroidOptions(
        requiresNetworkConnectivity: true,
        requiresExternalPower: true,
        targetPeriodInMinutes: 15),
    IOSOptions(
        requiresNetworkConnectivity: true,
        requiresExternalPower: true,
        taskIdentifier: "com.jimdo.uchida001tmhr.simple_work_manager.process"));

requiresNetworkConnectivity and requiresExternalPower must be set as following section. targetPeriodInMinutes specifies minimum interval of background process, minimum value is 15. taskIdentifier must be same as "Permitted background task scheduler identifier" of Info of Xcode. taskIdentifier must be unique, then must contain your domain identifier.

Options(Constraints(Experimental approach)) #

Simple Work Manager can specify the constraints such that requiresNetworkConnectivity and requiresExternalPower. The behaviors according to these constraints are as following tables:

Android #

                              
◯: callback function will be called in background
△: callback function will be called but its interval is long
×: callback function wil not be called in background
requiresExternalPower
NULL
FALSE
TRUE
Power Plug in
Power Plug off
Power Plug in
Power Plug off
Power Plug in
Power Plug off
requiresNetworkConnectivity NULL WiFi ON
×
WiFi OFF
×
FALSE WiFi ON
×
WiFi OFF
×
TRUE WiFi ON
×
WiFi OFF
×
×
×
×
×
×

iOS #

                              
◯: callback function will be called in background
△: callback function will be called but its interval is long
×: callback function wil not be called in background
requiresExternalPower
NULL
FALSE
TRUE
Power Plug in
Power Plug off
Power Plug in
Power Plug off
Power Plug in
Power Plug off
requiresNetworkConnectivity NULL WiFi ON
×
×
×
×
WiFi OFF
×
×
×
×
FALSE WiFi ON
×
×
×
×
WiFi OFF
×
×
×
TRUE WiFi ON
×
×
×
WiFi OFF
×
×
×
×
×
×

SUGGESTION FOR CONTRAINTS #

Set requiresExternalPower and requiresNetworkConnectivity to TRUE and plug external power IN to execute backgroud process continously.

Cancel the schedule #

_simpleWorkManagerPlugin.cancel();

CAUTION #

App must not killed to invoke callback function.
In iOS, app must be in background to invoke callback function.