Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capawesome-team/capacitor-background-task
⚡️ Capacitor plugin for running background tasks.
https://github.com/capawesome-team/capacitor-background-task
List: capacitor-background-task
capacitor capacitor-community capacitor-ios capacitor-plugin capawesome ios
Last synced: 3 months ago
JSON representation
⚡️ Capacitor plugin for running background tasks.
- Host: GitHub
- URL: https://github.com/capawesome-team/capacitor-background-task
- Owner: capawesome-team
- License: mit
- Archived: true
- Created: 2021-03-22T21:24:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-01T07:18:36.000Z (over 1 year ago)
- Last Synced: 2024-04-15T12:22:01.387Z (7 months ago)
- Topics: capacitor, capacitor-community, capacitor-ios, capacitor-plugin, capawesome, ios
- Language: Swift
- Homepage: https://capawesome.io/plugins/background-task/
- Size: 836 KB
- Stars: 51
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-capacitor - Background tasks - A native plugin for running background tasks. ([Capawesome plugins](https://capawesome.io/))
README
## ⚠️ Deprecated repository
**This project has been moved to the following monorepo: [capawesome-team/capacitor-plugins](https://github.com/capawesome-team/capacitor-plugins).**
-----
Background Task
@capawesome/capacitor-background-task
Capacitor plugin for running background tasks.## Maintainers
| Maintainer | GitHub | Social |
| ---------- | ----------------------------------------- | --------------------------------------------- |
| Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |## Sponsors
This is an MIT-licensed open source project.
It can grow thanks to the support by these awesome people.
If you'd like to join them, please read more [here](https://github.com/sponsors/capawesome-team).## Installation
```bash
npm install @capawesome/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](https://github.com/robingenz/capacitor-plugin-demo)
## Usage
```typescript
import { App } from '@capacitor/app';
import { BackgroundTask } from '@capawesome/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)
* [`finish(...)`](#finish)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)### beforeExit(...)
```typescript
beforeExit(cb: () => void) => Promise
```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(...)
```typescript
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](https://developer.apple.com/documentation/uikit) is used.
Read more about the implementation and any limitations [here](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_time).### Android
There is currently no ready implementation on **Android**.
It's planned to add the support in the near future.## Changelog
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-background-task/blob/master/CHANGELOG.md).
## License
See [LICENSE](https://github.com/capawesome-team/capacitor-background-task/blob/master/LICENSE).