React Native Background Geofencing
A reliable React Native geofencing library, that works in the background and survives device restarts.
WARNING: Currently only supports Android devices. Plans for iOS are underway
Getting started
$ yarn add react-native-background-geofencing
Android
Mostly automatic installation (for RN < 0.60)
$ react-native link react-native-background-geofencing
Permissions
Add the following permissions to your AndroidManifest.xml
Usage
1. Create an async JavaScript task file that will handle Geofence events
$ touch myTask.js
myTask.js
2. Place the following code inside The task will be executed in the background even after the device restarts.
; { // handle Geofence updates here if event === RNGeofenceEventENTER console; if event === RNGeofenceEventERROR console; }
3. Configure your JavaScript task and/or webhook
Add the following in your app's index.js
file.
;;;; ; // If you'd like to ship the events to a server use this.// Its guaranteed to run when the device has an internet connection using Android's Work manager API ; AppRegistry;
4. Add / Remove Geofences
; const geofence = id: 'mygeofence' lat: -129273 lng: 36820389; await RNBackgroundGeofencing; await RNBackgroundGeofencing;
Contributions
Are welcomed ♥️ especially those specifically addressing iOS support and bug fixes.