react-native-ble-plx
react-native-ble-plx copied to clipboard
React Native BLE library
About this library
This is React Native Bluetooth Low Energy library wrapping Multiplatform Ble Adapter.
It supports:
- observing device's Bluetooth adapter state
- scanning BLE devices
- making connections to peripherals
- discovering services/characteristics
- reading/writing characteristics
- observing characteristic notifications/indications
- reading RSSI
- negotiating MTU
- background mode on iOS
- turning the device's Bluetooth adapter on
It does NOT support:
- bluetooth classic devices.
- communicating between phones using BLE (Peripheral support)
- bonding peripherals
Compatibility
This version (2.x) breaks compatibility with old RN versions. Please check old README (1.x) for the old instructions or migration guide.
| React Native | 2.0.0 |
|---|---|
| 0.63.3 | :white_check_mark: |
| 0.62.2 | :white_check_mark: |
| 0.61.5 | :white_check_mark: |
| 0.60.6 | :white_check_mark: |
Recent Changes
2.0.3
- Updated MultiplatformBleAdapter to version 0.1.9
All previous changes
Documentation & Support
Interested in React Native project involving Bluetooth Low Energy? We can help you!
Documentation can be found here.
Quick introduction can be found here
Contact us at intent.
Contact us at Gitter if you have any questions, feedback or want to help!
Configuration & Installation
Expo
- Make sure your Expo project is ejected (formerly: detached). You can read how to do it here and here. (only for expo)
- Follow steps for iOS/Android.
iOS (example setup)
npm install --save react-native-ble-plx- Enter
iosfolder and runpod update - Add
NSBluetoothAlwaysUsageDescriptionininfo.plistfile. (it is a requirement since iOS 13) - If you want to support background mode:
- In your application target go to
Capabilitiestab and enableUses Bluetooth LE AccessoriesinBackground Modessection. - Pass
restoreStateIdentifierandrestoreStateFunctiontoBleManagerconstructor.
- In your application target go to
Android (example setup)
-
npm install --save react-native-ble-plx -
In top level
build.gradlemake sure that min SDK version is at least 18:buildscript { ext { ... minSdkVersion = 21 ... -
In
build.gradlemake sure to add jitpack repository to known repositories:allprojects { repositories { ... maven { url 'https://www.jitpack.io' } } } -
(Optional) In
AndroidManifest.xml, add Bluetooth permissions and update<uses-sdk/>:<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-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- Add this line if your application always requires BLE. More info can be found on: https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#permissions --> <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> ...
Troubleshooting
Problems with Proguard
Add this to your app/proguard-rules.pro
-dontwarn com.polidea.reactnativeble.**