React Native GPS State
React Native Listener for GPS status changes
This lib will emitevent wheneaver the GPS status change, like when the permission was rejected or user disable Location service in system Settings.
Instalation
- Add library to project
yarn add react-native-gps-state
- OR
npm install --save react-native-gps-state
- Link library to project
react-native link react-native-gps-state
If the link fails, do a manual setup:
Android
android/settings.gradle
include ':react-native-gps-state'project(':react-native-gps-state').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gps-state/android')
android/app/build.gradle
dependencies { ... compile project(':react-native-gps-state')}
MainApplication.java
On top, where imports are:
Add the new GPSStatePackage()
class to your list of exported packages.
@Overrideprotected List<ReactPackage> { return Arrays.;}
Usage
Constants
Platform | Status Code | Constant | Description |
---|---|---|---|
IOS/Android | 0 | NOT_DETERMINED | The user has not yet made a choice regarding whether this app can use location services. |
IOS/Android | 1 | RESTRICTED | This app is not authorized to use location services. |
IOS/Android | 2 | DENIED | The user explicitly denied the use of location services for this app or location services are currently disabled in Settings. |
IOS/Android | 3 | AUTHORIZED | This app is authorized to use location services. |
IOS | 3 | AUTHORIZED_ALWAYS | This app is authorized to start location services at any time. |
IOS | 4 | AUTHORIZED_WHENINUSE | This app is authorized to start most location services while running in the foreground |
Methods
//Open a system dialog requesting permission//authType could be one of `AUTHORIZED_ALWAYS` or `AUTHORIZED_WHENINUSE`GPSState
//Open the system Settings to enable user to toggle Location on.GPSState
//Open the system Settings in app details, so the user could manage all permissions in the `Permissions` tab//in Android bellow M will fallback to `openLocationSettings()`GPSState
//ANDROID ONLY//return true if system version is Marshmallow or aboveGPSState
//return true if the location permission is grantedGPSState
//return true if the location permission is deniedGPSState
//Get the current GPS stateGPSState
Listeners
...{ GPSState GPSState} { GPSState}