Git Product home page Git Product logo

react-native-background-task's Introduction

react-native-background-task

NB: this is a fork of react-native-background-task

Register a single JS background task to run at periodic intervals, on Android and iOS React Native apps, even when the app is closed.

This builds on top of the native modules provided by the following two libraries:

To achieve a unified API, this package exposes the lowest common denominator (e.g. only support for a single task, even though Android can support multiple).

For more per-platform flexibility, those libraries should be used individually.

Installation

$ npm install --save https://github.com/MaximusBaton/react-native-background-task.git

API

register(task, options)

Define the task that this module should be executing.

  • Will overwrite any previously registered task.
  • Should be called at the root of your main app entrypoint file.
  • Should console.error if it can't register the task

Parameters:

  • task: required () => void - Function to be executed in the background

  • options: ?object - Any configuration you want to be set with the task. Note that most of these will only work on one platform.

    • period number - (Android only) Desired number of seconds between each execution of the task. Even on Android, the OS will only take this as a recommendation, and will likely enforce a minimum of 15 minutes (similar to iOS). Default is 9000 (15 minutes)
    • timeout number - (Android only) Number of seconds the task will have to execute. iOS has a hardcoded limit of 30 seconds. Default 30 seconds.

cancel()

Cancels any currently registered task.

finish()

Must be called at the end of your task to indicate to the OS that it's finished. (Only required on iOS, no-op on Android).

Example

Simple

import React from 'react'
import { Text } from 'react-native'
import BackgroundTask from 'react-native-background-task'

BackgroundTask.register(() => {
  console.log('Hello from a background task')
  BackgroundTask.finish()
})

class MyApp extends React.Component {
  render() {
    return <Text>Hello world</Text>
  }
}

react-native-background-task's People

Contributors

maximusbaton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.