Git Product home page Git Product logo

react-native-connectivity-status's Introduction

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

react-native-connectivity-status's People

Contributors

federicoboschini avatar awhite avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.