This package has been deprecated

Author message:

This project was renamed to @capawesome/capacitor-background-task.

@robingenz/capacitor-background-task
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published


Background Task

@robingenz/capacitor-background-task

Capacitor plugin for running background tasks.


Maintainers

Maintainer GitHub Social
Robin Genz robingenz @robin_genz

Installation

npm install @robingenz/capacitor-background-task
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { App } from '@capacitor/app';
import { BackgroundTask } from '@robingenz/capacitor-background-task';

App.addListener('appStateChange', async ({ isActive }) => {
  if (isActive) {
    return;
  }
  // The app state has been changed to inactive.
  // Start the background task by calling `beforeExit`.
  const taskId = await BackgroundTask.beforeExit(async () => {
    // Run your code...
    // Finish the background task as soon as everything is done.
    BackgroundTask.finish({ taskId });
  });
});

API

beforeExit(...)

beforeExit(cb: () => void) => Promise<CallbackID>

Call this method when the app moves to the background. It allows the app to continue running a task in the background.

On iOS this method should be finished in less than 30 seconds.

Only available for Android and iOS.

Param Type
cb () => void

Returns: Promise<string>


finish(...)

finish(options: FinishOptions) => void

Finish the current background task. The OS will put the app to sleep.

Only available for Android and iOS.

Param Type
options FinishOptions

Interfaces

FinishOptions

Prop Type
taskId CallbackID

Type Aliases

CallbackID

string

Quirks

iOS

On iOS the UIKit framework is used. Read more about the implementation and any limitations here.

Android

There is currently no ready implementation on Android. It's planned to add the support in the near future.

Changelog

See CHANGELOG.md.

License

See LICENSE.

Readme

Keywords

Package Sidebar

Install

npm i @robingenz/capacitor-background-task

Weekly Downloads

64

Version

1.0.1

License

MIT

Unpacked Size

25.3 kB

Total Files

28

Last publish

Collaborators

  • robingenz