3.3.1 โ€ข Published 3 months ago

react-native-background-runner v3.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

๐ŸŒŸreact-native-background-runner๐ŸŒŸ

ย 

Installation

  • Through Yarn:

yarn add react-native-background-runner
  • Through NPM:

npm install react-native-background-runner

ย 

Features ๐Ÿš€๐Ÿš€

  • ๐Ÿ› ๏ธ Our package is designed to tackle background-related issues on both iOS and Android platforms.

  • ๐Ÿงช Test Phase: We are currently in the initial testing phase, with many exciting enhancements on the way.

  • ๐Ÿƒโ€โ™‚๏ธ Background Runner on iOS: We've implemented a unique solution using the Location Core API trick to ensure seamless background running on iOS.

  • ๐Ÿ“ Live Background Location Tracker (Android): Our package includes a powerful live background location tracker specifically built for Android devices.**

  • ๐Ÿ†• Coming Soon to iOS: Stay tuned for the upcoming release, which will include background location tracking functionality for iOS as well.

ย 

Preview

PlatformDemo
IOS<img alt='demo-ios'
Android

ย 

Demo-For-Location-Tracker-(ANDROID-ONLY)

Traking Demo (Android only)Gif Demo
Basic Demo<img alt='demo-ios'
Live Demo

ย 

IOS-Setup

Let us not forget the mandatory strings NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription inside Our Info.plist. These are needed to display the permissions popup.

+   <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
+	  <string>App Uses Location Services to allow background operations while performing long running tasks,  this insures data integrity on our side, and offers a better user experience</string>
+	  <key>NSLocationWhenInUseUsageDescription</key>
+	  <string>App Uses Location Services to allow background operations while performing long running tasks, this insures data integrity on our side, and offers a better user experience</string>

alt text

set the right capabilities for app

alt text

ย 

Android-Setup

Add the following code to android/app/src/main/AndroidManifest.xml:

<manifest ...>
  ...
  <application ...>
    ...
+    <service android:name="com.backgroundrunner.BackgroundRunnerTask" />
  </application>
</manifest>

After adding the code to the AndroidManifest.xml file, save the changes and continue with the Usage instructions.

ย 

Usage

Wrapper Component

To handle the lifecycle of your app, use the Runnable wrapper component. Place your app component within the Runnable component as follows:

<Runnable>
  {/* Your app component */}
</Runnable>

ย 

Background Task

To perform a background task, follow these steps:

  • Define an asynchronous task function that takes taskData as a parameter. This function can have different implementations based on the platform.
  const task = async (taskData) => {
    await new Promise(async () => {
      const { delay } = taskData;
      for (let i = 0; Service.isRunning(); i++) {
        setRunnedValue(i);
        console.log('Runned -> ', i);
        await sleep(delay);
      }
    });
  };
  • Use the toggleBackground function to control the background task. It checks if the background service is running and either starts or stops it accordingly.
const toggleBackground = async (runnerTask) => {
  if (!Service.isRunning()) {
    try {
      await Service.startRunnerTask(runnerTask, options);
      console.log('Successful start!');
    } catch (e) {
      console.log('Error', e);
    }
  } else {
    console.log('Stop background service');
    await Service.stop();
  }
};

Call toggleBackground(task) to start or stop the background task.

ย 

Location Tracker

For now, the location tracker only supports Android. Use the following methods to work with the location tracker:

  • Start watching the user's location even if the app is closed:
Service.watchLocation(
  (location) => console.log('location =>>> ', location),
  options
);
  • Stop watching the user's location:
Service.stopWatching();
  • Listen for location update events:
DeviceEventEmitter.addListener('locationUpdate', handleLocationUpdate);

โš ๏ธ Please note that the location tracker is currently only supported on Android.

ย 

License

MIT


3.3.1

3 months ago

3.2.2

3 months ago

3.3.0

3 months ago

3.2.1

3 months ago

3.2.0

3 months ago

3.1.2

9 months ago

3.1.1

10 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.3.0

10 months ago

2.2.2

10 months ago

2.2.1

10 months ago

2.1.1

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.26

10 months ago

1.0.25

10 months ago

1.0.24

10 months ago

1.0.23

10 months ago

1.0.22

10 months ago

1.0.21

10 months ago

1.0.20

10 months ago

1.0.19

10 months ago

1.0.18

10 months ago

1.0.17

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago