forked from rn-bridge/react-native-geofencing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e84513b
commit 770eab1
Showing
38 changed files
with
22,652 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,172 @@ | ||
# @rn-bridge/react-native-geofencing | ||
|
||
Native modules to determine if a location is within defined geographical boundaries | ||
> [!NOTE] | ||
> Native module to determine if a location is within defined geographical boundaries. Geofencing combines awareness of the user's current location with awareness of the user's proximity to locations that may be of interest. To mark a location of interest, you specify its latitude and longitude. To adjust the proximity for the location, you add a radius. The latitude, longitude, and radius define a geofence, creating a circular area, or fence, around the location of interest. | ||
Fully compatible with TypeScript. | ||
|
||
## Supported platforms | ||
|
||
| Platform | Support | | ||
|---|---| | ||
| iOS | ✅ | | ||
| Android | ✅ | | ||
| Web | ❌ | | ||
| Windows | ❌ | | ||
| macOS | ❌ | | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install @rn-bridge/react-native-geofencing | ||
``` | ||
or | ||
|
||
## Usage | ||
```sh | ||
yarn add @rn-bridge/react-native-geofencing | ||
``` | ||
|
||
## Configuration and Permissions | ||
|
||
```js | ||
import { multiply } from '@rn-bridge/react-native-geofencing'; | ||
### iOS | ||
|
||
To enable geofence in your app, you need to add the `NSLocationWhenInUseUsageDescription` and `NSLocationAlwaysAndWhenInUseUsageDescription` keys to your `Info.plist` file. If your app supports iOS 10 or earlier, you must also include the `NSLocationAlwaysUsageDescription` key. Without these keys, geofence requests will fail. | ||
|
||
To enable geofence while the app runs in the background, add the `NSLocationAlwaysUsageDescription` key to `Info.plist`. | ||
|
||
It’s important to ensure you’ve enabled the necessary background modes. Here’s how to do so: | ||
|
||
- Go to your Xcode project settings. | ||
- Select your target. | ||
- Go to the `Signing & Capabilities` tab. | ||
- Enable `Background Modes` capability. | ||
- Check `Location updates` | ||
|
||
<img width="743" alt="Screenshot 2024-08-15 at 7 27 40 PM" src="https://github.com/user-attachments/assets/87d0215e-e1c9-45b0-9488-4f0e9509a21b"> | ||
|
||
// ... | ||
<br></br> | ||
Your `Info.plist` should look like this, Explain why the background location is required!! | ||
|
||
const result = await multiply(3, 7); | ||
```java | ||
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key> | ||
<string>This app need your location to provide best feature based on location</string> | ||
<key>NSLocationWhenInUseUsageDescription</key> | ||
<string>This app need your location to provide best feature based on location</string> | ||
<key>NSLocationAlwaysUsageDescription</key> | ||
<string>This app need your location to provide best feature based on location in background</string> | ||
<key>UIBackgroundModes</key> | ||
<array> | ||
<string>location</string> | ||
</array> | ||
``` | ||
|
||
### Android | ||
|
||
## Contributing | ||
The first step in requesting geofence monitoring is to request the necessary permissions. To use geofencing, your app must request the following: | ||
|
||
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
- `ACCESS_FINE_LOCATION` | ||
- `ACCESS_BACKGROUND_LOCATION` if your app targets Android 10 (API level 29) or higher | ||
|
||
## License | ||
Your `AndroidManifest.xml` should look liks this | ||
|
||
MIT | ||
```java | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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.WAKE_LOCK" /> | ||
|
||
</manifest> | ||
``` | ||
|
||
## Summary | ||
|
||
### Methods | ||
|
||
* [`addGeofence`](#addGeofence) | ||
* [`removeGeofence`](#removeGeofence) | ||
* [`getRegisteredGeofences`](#getRegisteredGeofences) | ||
|
||
### Listeners | ||
|
||
* [`onEnter`](#onEnter) | ||
* [`onExit`](#onExit) | ||
* [`removeOnEnterListener`](#removeOnEnterListener) | ||
* [`removeOnExitListener`](#removeOnExitListener) | ||
|
||
--- | ||
|
||
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) | ||
## Usage | ||
|
||
### addGeofence | ||
```js | ||
import { addGeofence } from '@rn-bridge/react-native-geofencing'; | ||
|
||
const response = await addGeofence({ | ||
id: 'a9957259-8036-4dcb-974c-34eae9b44bdb', | ||
latitude: 16.153062, | ||
longitude: 100.281585, | ||
radius: 500 | ||
}) | ||
console.log(response) // { success: true, id, type: "add" } | ||
``` | ||
Supported options: | ||
* `id` (String) - Set the ID of the geofence. This is a string to identify this geofence. | ||
* `latitude` (Double) - The latitude and longitude are used to define the precise geographical location of the geofence’s center. This ensures accurate detection when a device enters or exits the geofenced area. | ||
* `longitude` (Double) - The latitude and longitude are used to define the precise geographical location of the geofence’s center. This ensures accurate detection when a device enters or exits the geofenced area. | ||
* `radius` (Integer) - The radius defines the boundary of the geofence around the central point (latitude and longitude). It allows for flexibility in creating different-sized geofences | ||
|
||
### removeGeofence | ||
```javascript | ||
import { removeGeofence } from '@rn-bridge/react-native-geofencing'; | ||
|
||
const response = await removeGeofence(id) | ||
console.log(response) // { success: true, id, type: "remove" } | ||
``` | ||
Supported options: | ||
* `id` (String) - The ID uniquely identifies a geofence, enabling precise and efficient removal by referencing the specific geofence without ambiguity. | ||
|
||
### getRegisteredGeofences | ||
```javascript | ||
import { getRegisteredGeofences } from '@rn-bridge/react-native-geofencing'; | ||
|
||
const response = await getRegisteredGeofences() | ||
console.log(response) // [id, ...] | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> ## Listening for location transitions | ||
### onEnter | ||
```javascript | ||
import { Geofence, Events } from '@rn-bridge/react-native-geofencing'; | ||
|
||
Geofence.onEnter((ids: string[]) => { | ||
console.log(Events.Enter, ids); | ||
}); | ||
``` | ||
|
||
### onExit | ||
```javascript | ||
import { Geofence, Events } from '@rn-bridge/react-native-geofencing'; | ||
|
||
Geofence.onExit((ids: string[]) => { | ||
console.log(Events.Exit, ids); | ||
}); | ||
``` | ||
|
||
### removeOnEnterListener | ||
```javascript | ||
import { Geofence } from '@rn-bridge/react-native-geofencing'; | ||
|
||
Geofence.removeOnEnterListener() | ||
``` | ||
|
||
### removeOnExitListener | ||
```javascript | ||
import { Geofence } from '@rn-bridge/react-native-geofencing'; | ||
|
||
Geofence.removeOnExitListener() | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
ReactNativeGeofencing_kotlinVersion=1.7.0 | ||
## For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx1024m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
# | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. For more details, visit | ||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects | ||
# org.gradle.parallel=true | ||
#Fri Aug 16 11:45:03 IST 2024 | ||
ReactNativeGeofencing_compileSdkVersion=33 | ||
ReactNativeGeofencing_kotlinVersion=1.9.24 | ||
ReactNativeGeofencing_minSdkVersion=21 | ||
ReactNativeGeofencing_targetSdkVersion=31 | ||
ReactNativeGeofencing_compileSdkVersion=31 | ||
ReactNativeGeofencing_ndkversion=21.4.7075529 | ||
ReactNativeGeofencing_ndkversion=26.1.10909125 | ||
ReactNativeGeofencing_targetSdkVersion=33 | ||
android.useAndroidX=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.