Skip to content

@capgo/capacitor-background-task

Expo-style named background tasks for Capacitor apps, backed by Android WorkManager and iOS BGTaskScheduler.

Use @capgo/capacitor-background-task when your Capacitor app needs periodic background fetch work such as sync, cache refreshes, inbox polling, analytics flushing, or lightweight maintenance jobs.

The plugin follows the practical feature set of Expo BackgroundTask with named tasks, persistent registration, status checks, unregistering, a development trigger, and iOS expiration events.

  • defineTask - Register the JavaScript callback for a named task.
  • registerTaskAsync - Persist and schedule a periodic task.
  • unregisterTaskAsync - Cancel future runs for one task.
  • isTaskRegisteredAsync - Check whether a task is registered.
  • getRegisteredTasksAsync - List currently registered task names.
  • getPendingTaskRunsAsync - Inspect native task events recorded before JavaScript was ready.
  • getStatusAsync - Check native background task availability.
  • triggerTaskWorkerForTestingAsync - Run registered tasks immediately during development.
  • addExpirationListener - Handle iOS expiration callbacks.
  • define, schedule, cancel, statusAsync, and finish - Compatibility helpers for react-native-background-task.

Background tasks are not exact timers. Android and iOS decide when to run scheduled work based on battery, network, app usage, and system policy.

PlatformNative schedulerImportant behavior
AndroidWorkManagerPeriodic work has a 15-minute minimum interval.
iOSBGTaskSchedulerminimumInterval is an earliest begin date, not a guaranteed cadence.
WebTest-only fallbackNo real background scheduler is available.
MethodDescription
defineTaskDefines the JavaScript callback for a named task.
registerTaskAsyncRegisters a named periodic background task.
unregisterTaskAsyncCancels future task runs.
isTaskRegisteredAsyncReturns whether a task is registered.
getRegisteredTasksAsyncLists registered task names.
getPendingTaskRunsAsyncLists native task events waiting to be finished.
getStatusAsyncReturns whether native background scheduling is available.
triggerTaskWorkerForTestingAsyncTriggers registered tasks for development and QA.
addExpirationListenerListens for iOS expiration events.

This reference is synced from src/definitions.ts in capacitor-background-task.