129
GitHub - Polidea/react-native-ble-plx: React Native BLE library
source link: https://github.com/Polidea/react-native-ble-plx
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
About this library
This is React Native Bluetooth Low Energy library using RxBluetoothKit and RxAndroidBle under the hood.
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
- turning the device's Bluetooth adapter on
What this library does NOT support:
- communicating between phones using BLE (Peripheral support)
- bonding peripherals
Recent Changes
1.0.1
- Fix possible ConcurrentModificationException in Android BleModule.
- Workaround for when
canSendWriteWithoutResponse
would return false on iOS. - Fixed low severity vulnerabilities reported by npm in development dependencies.
Documentation & Support
Interested in React Native project involving Bluetooth Low Energy? We can help you!
Documentation can be found here.
Contact us at Gitter if you have any questions, feedback or want to help!
Configuration & Installation
iOS (pure react-native, example setup)
npm install --save react-native-ble-plx
react-native link react-native-ble-plx
- Add empty Swift file if you don't have at least one:
- Select File/New/File...
- Choose Swift file and click Next.
- Name it however you want, select your targets and create it.
- Accept to create Objective-C bridging header.
- Minimal supported version of iOS is 8.0
- If you want to support background mode:
- In your application target go to
Capabilities
tab and enableUses Bluetooth LE Accessories
inBackground Modes
section. - Pass
restoreStateIdentifier
andrestoreStateFunction
toBleManager
constructor.
- In your application target go to
iOS (expo/Podfile, example setup)
- Make sure your Expo project is detached. You can read how to do it here and here.
npm install --save react-native-ble-plx
react-native link react-native-ble-plx
- Add empty Swift file if you don't have at least one:
- Select File/New/File...
- Choose Swift file and click Next.
- Name it however you want, select your application target and create it.
- Accept to create Objective-C bridging header.
- Update your
ios/Podfile
to contain:pod 'react-native-ble-plx', :path => '../node_modules/react-native-ble-plx' pod 'react-native-ble-plx-swift', :path => '../node_modules/react-native-ble-plx'
- Enter
ios
folder and runpod update
- Minimal supported version of iOS is 8.0
- If you want to support background mode:
- In your application target go to
Capabilities
tab and enableUses Bluetooth LE Accessories
inBackground Modes
section. - Pass
restoreStateIdentifier
andrestoreStateFunction
toBleManager
constructor.
- In your application target go to
Android (example setup)
npm install --save react-native-ble-plx
react-native link react-native-ble-plx
- In
build.gradle
ofapp
module make sure that min SDK version is at least 18:
android { ... defaultConfig { minSdkVersion 18 ...
- 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_COARSE_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"/> <uses-sdk android:minSdkVersion="18" ...
Troubleshooting
Problems with Proguard
Add this to your app/proguard-rules.pro
-dontwarn com.polidea.reactnativeble.**
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK