GithubHelp home page GithubHelp logo

davistsin / react-native-permission-hooks Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 359 KB

License: MIT License

Java 37.14% JavaScript 7.55% Ruby 14.58% Swift 0.27% C 0.41% Objective-C 10.26% Objective-C++ 7.45% TypeScript 22.34%

react-native-permission-hooks's Introduction

react-native-permission-hooks

react native permission hooks.

Installation

npm install react-native-permission-hooks

This library depends on react-native-permissions, so you also need to

npm install react-native-permissions

Usage

Bluetooth Permission

export default function App() {
  const { status: bluetoothPerStatus, request: requestBluetoothPer } =
    useBluetoothPermission();

  return (
    <View style={styles.container}>
      <Text>{`Bluetooth permission: ${bluetoothPerStatus}`}</Text>
      <Button
        title="request bluetooth permission"
        onPress={() => {
          requestBluetoothPer();
        }}
      />
    </View>
  );
}

Android Intro

  • Android <6: return default GRANTED.
  • Android 6-11: check android.permission.ACCESS_FINE_LOCATION permission, in order to scan.
  • Android >=12: check android.permission.BLUETOOTH_SCAN, android.permission.BLUETOOTH_ADVERTISE, android.permission.BLUETOOTH_CONNECT permissions.

The following permissions need to be added to the manifest file.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.BLUETOOTH"/>
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

  <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
</manifest>

iOS Intro

Unlike Android, iOS only needs Bluetooth permissions to perform all Bluetooth functions: open/scan/connect.

In your Info.plist, add

<?xml version="1.0" encoding="UTF-8"?>
<dict>
  <key>NSBluetoothPeripheralUsageDescription</key>
  <string>Need open bluetooth</string>
  <key>NSBluetoothAlwaysUsageDescription</key>
  <string>Need open bluetooth</string>
</dict>

And import CoreBluetooth.framework. "Target" -> "General" -> "Frameworks, Libraries, and Embedded Content" -> + CoreBluetooth.framework -> "Embed & Sign"

TODO Camera Permission

TODO Location Permission

TODO Storage Permission

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

react-native-permission-hooks's People

Watchers

 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.