npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@okhi/react-native-background-geofencing

v1.5.0

Published

A reliable React Native Geofencing library, that works in the background and survives device restarts

Downloads

1

Readme

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />

</manifest>

Usage

1. Create an async JavaScript task file that will handle Geofence events

$ touch myTask.js

2. Place the following code inside myTask.js

The task will be executed in the background even after the device restarts.

import {RNGeofenceEvent} from 'react-native-background-geofencing';
export default async function myTask({event, data}) {
  // handle Geofence updates here
  if (event === RNGeofenceEvent.ENTER) {
    console.log(`welcome to ${data.lat},${data.lng}`);
  }
  if (event === RNGeofenceEvent.ERROR) {
    console.log(`Opps, something went wrong: ${data.errorMessage}`);
  }
}

3. Configure your JavaScript task and/or webhook

Add the following in your app's index.js file.

import {AppRegistry} from 'react-native';
import {
  configureJSTask,
  configureWebhook,
} from 'react-native-background-geofencing';
import App from './App';
import myTask from './myTask.js';

configureJSTask({
  task: myTask,
  // Required to enable your task to run as an Android foreground service
  notification: {
    title: "Don't mind me",
    text: "I'm just a notification",
  },
});

// 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

configureWebhook({
  url: 'https://myapi.com/geofences',
  headers: {
    foo: 'Bar',
  },
});

AppRegistry.registerComponent(appName, () => App);

4. Add / Remove Geofences

import RNBackgroundGeofencing from 'react-native-background-geofencing';

const geofence = {
  id: 'mygeofence',
  lat: -1.29273,
  lng: 36.820389,
};

await RNBackgroundGeofencing.add(geofence);

await RNBackgroundGeofencing.remove(geofence.id);

Contributions

Are welcomed ♥️ especially those specifically addressing iOS support and bug fixes.