Skip to content

matiere-noire/react-native-connectivity-status

 
 

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.isLocationEnabled()

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

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

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

// Ask user to turn on Location Services
ConnectivityManager.enableLocation()

// Ask user to turn on Bluetooth
ConnectivityManager.enableBluetooth()

ATTENTION: On iOS the enableLocation method won't ask the user for Location Permissions but will redirect to iOS location settings screen to allow the user to enable Location Services. In case Location Services are active but Location Permissions have yet to be asked to the user the method call will throw an error.

ATTENTION: Starting from iOS 11 redirect to specific Settings page has been disabled, so the enableLocation method will only redirect to the Settings main screen.


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 54.4%
  • Objective-C 40.8%
  • JavaScript 4.8%