Skip to content

budget-coder/react-native-connectivity-status

This branch is 1 commit ahead of nearit/react-native-connectivity-status:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0e31e39 · Feb 20, 2022

History

67 Commits
Oct 11, 2017
Feb 20, 2022
Aug 29, 2018
Oct 10, 2017
Oct 10, 2017
Oct 11, 2017
Jan 19, 2018
Oct 10, 2017
Sep 11, 2018
Aug 29, 2018
Sep 12, 2019
Aug 28, 2019

Repository files navigation

React-native-connectivity-status

A React Native module to check Bluetooth and Location status on Android and iOS

license Build Status npm

React Native platforms

Gitter

Getting started

Add react-native-connectivity-status module to your project

$ yarn add react-native-connectivity-status

And link it

$ react-native link react-native-connectivity-status


Usage

Check Status

Interactively check Location Services and Bluetooth status

import ConnectivityManager from 'react-native-connectivity-status'

// Check if Location Services are enabled
const locationServicesAvailable = await ConnectivityManager.areLocationServicesEnabled()

// Check Location permission
const locationPermission = await ConnectivityManager.isLocationPermissionGranted()
switch(locationPermission) {
    case "Location.Permission.Denied":
    	// ...
        break;
    case "Location.Permission.Granted.Always":
        // ...
        break;
    case "Location.Permission.Granted.WhenInUse":
	// ...
        break;
    default:
        // ...
}

// Check if Bluetooth is ON
const bluetoothIsOn = await ConnectivityManager.isBluetoothEnabled()

Note: On Android, Location permission state will map on Location.Permission.Denied and Location.Permission.Granted.Always only.

Subscribe to updates

import ConnectivityManager from 'react-native-connectivity-status'

const connectivityStatusSubscription = ConnectivityManager.addStatusListener(({ eventType, status }) => {
	switch (eventType) {
		case 'bluetooth':
					console.log(`Bluetooth is ${status ? 'ON' : 'OFF'}`)
				break
		case 'location':
					console.log(`Location Services are ${status ? 'AVAILABLE' : 'NOT available'}`)
				break
	}
})
...
// Remeber to unsubscribe from connectivity status events
connectivityStatusSubscription.remove()

Enable services

NOTE: Due to possible app rejection from Apple (caused by illegal usage of private URL Scheme "prefs:root" or "App-Prefs:root"), methods for enabling bluetooth and location services have been removed from this module.


Made with ✨ & ❤️ by Mattia Panzeri and contributors

About

A ReactNative module to check Bluetooth and Location status on Android and iOS

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 48.9%
  • Objective-C 41.1%
  • Ruby 5.3%
  • JavaScript 4.7%