Git Product home page Git Product logo

react-native-cron-job's Introduction

react-native-cron-job

Getting started

$ npm install react-native-cron-job --save

Mostly automatic installation

$ react-native link react-native-cron-job

Usage

This package allows you to create cron job locally in your react-native app. You can schedule your task everyday at a particular time. The Cron job will get executed everyday at the given time even if the app is closed.

index.js

Add the below code in your index.js file.

import CronJob from "react-native-cron-job";
const CronJobTask = async () => {

      // Do your task here.

      // Be sure to call completeTask at the end.
      CronJob.completeTask();
};
AppRegistry.registerHeadlessTask('CRONJOB', () => CronJobTask);
AppRegistry.registerComponent(appName, () => App);

AndroidManifest.xml

In your AndroidManifest.xml file add the below code in application tag -

        <service
            android:name="com.cronjob.CJService"
            android:enabled="true"
            android:exported="false" >
        </service>

        <service
            android:name="com.cronjob.CJEventService">
        </service>

        <receiver
            android:name="com.cronjob.BootReceiver"
            android:enabled="true"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

Additionally add below permissions in AndroidManifest.xml -

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

Start Cron Job

To start cron job just execute the below code. Below function takes 2 integer arguments which is hour and minute (the time at which cronjob starts everyday even if the app is closed). place this code anywhere where you want to start your task. Time range is 0 <= hour <= 23 , 0 <= minute <= 59

CronJob.startCronJob(22,12); // starts cronjob everyday at 10:12 PM

react-native-cron-job's People

Contributors

kathuriyarajat avatar mirceaciu avatar

Watchers

James Cloos 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.