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
- beacons
- Compatibility
- Recent Changes
- Documentation & Support
- Configuration & Installation
- Troubleshooting
- Releasing
- Contributions
For old RN versions (<0.60) please check old README (1.x) for the old instructions or migration guide.
| React Native | 3.1.2 |
|---|---|
| 0.81.4 | ✅ |
| 0.74.1 | ✅ |
| 0.69.6 | ✅ |
| Expo 51 | ✅ |
3.2.0
- Added Android Instance checking before calling its method, an error will be visible on the RN side
- Added information related to Android 14 to the documentation.
- Changed destroyClient, cancelTransaction, setLogLevel, startDeviceScan, stopDeviceScan calls to promises to allow error reporting if it occurs.
- Fixed one of the functions calls that clean up the BLE instance after it is destroyed.
Current version changes All previous changes
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.
Tested against Expo SDK 49 This package cannot be used in the "Expo Go" app because it requires custom native code. First install the package with yarn, npm, or
npx expo install.
After installing this npm package, add the config plugin to the plugins array of your app.json or app.config.js:
{
"expo": {
"plugins": ["react-native-ble-plx"]
}
}Then you should build the version using native modules (e.g. with npx expo prebuild command).
And install it directly into your device with npx expo run:android.
You can find more details in the "Adding custom native code" guide.
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and prebuild) the native app. If no extra properties are added, defaults will be used.
isBackgroundEnabled(boolean): Enable background BLE support on Android. Adds<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>to theAndroidManifest.xml. Defaultfalse.neverForLocation(boolean): Set to true only if you can strongly assert that your app never derives physical location from Bluetooth scan results. The location permission will be still required on older Android devices. Note, that some BLE beacons are filtered from the scan results. Android SDK 31+. Defaultfalse. WARNING: This parameter is experimental and BLE might not work. Make sure to test before releasing to production.modes(string[]): Adds iOSUIBackgroundModesto theInfo.plist. Options are:peripheral, andcentral. Defaults to undefined.bluetoothAlwaysPermission(string | false): Sets the iOSNSBluetoothAlwaysUsageDescriptionpermission message to theInfo.plist. Settingfalsewill skip adding the permission. Defaults toAllow $(PRODUCT_NAME) to connect to bluetooth devices.iosEnableRestoration(boolean): Opt-in to the iOS BLE state restoration subspec (disabled by default). When true, the Podfile will includereact-native-ble-plx/Restorationand the adapter will register with a restoration registry if present.iosRestorationIdentifier(string): Custom CBCentralManager restoration identifier. Written toInfo.plistasBlePlxRestoreIdentifierand passed toBleManagerfor state restoration. Defaults tocom.reactnativebleplx.restore.
Expo SDK 48 supports iOS 13+ which means
NSBluetoothPeripheralUsageDescriptionis fully deprecated. It is no longer setup in@config-plugins/[email protected]and greater.
{
"expo": {
"plugins": [
[
"react-native-ble-plx",
{
"isBackgroundEnabled": true,
"modes": ["peripheral", "central"],
"bluetoothAlwaysPermission": "Allow $(PRODUCT_NAME) to connect to bluetooth devices",
"iosEnableRestoration": true,
"iosRestorationIdentifier": "com.example.myapp.bleplx"
}
]
]
}
}- Make sure your Expo project is ejected (formerly: detached). You can read how to do it here. (only for Expo SDK < 43)
- 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
- Opt-in via the config plugin: set
iosEnableRestoration: trueand optionallyiosRestorationIdentifierto a stable string. - The plugin writes
BlePlxRestoreIdentifierintoInfo.plistand injects thereact-native-ble-plx/Restorationsubspec into your Podfile. - In JS, pass the same identifier to
BleManager:
const manager = new BleManager({
restoreStateIdentifier: 'com.example.myapp.bleplx',
restoreStateFunction: (restoredState) => {
// Rehydrate your app, reconnect devices, etc.
},
});- The Restoration subspec exposes a Swift adapter (
BlePlxRestorationAdapter) that will register with any restoration registry present in the host app (for example, a sharedBleRestorationRegistry). If no registry is present, it is a no-op.
Android (example setup)
-
npm install --save react-native-ble-plx -
In top level
build.gradlemake sure that min SDK version is at least 23:buildscript { ext { ... minSdkVersion = 23 ... -
In
build.gradlemake sure to add jitpack repository to known repositories:allprojects { repositories { ... maven { url 'https://www.jitpack.io' } } } -
In
AndroidManifest.xml, add Bluetooth permissions and update<uses-sdk/>:<manifest xmlns:android="http://schemas.android.com/apk/res/android"> ... <!-- Android >= 12 --> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <!-- Android < 12 --> <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /> <!-- common --> <uses-permission 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"/> ...
-
(Optional) In SDK 31+ You can remove
ACCESS_FINE_LOCATION(or mark it asandroid:maxSdkVersion="30") fromAndroidManifest.xmland addneverForLocationflag intoBLUETOOTH_SCANpermissions which says that you will not use location based on scanning eg:<uses-permission android:name="android.permission.INTERNET" /> <!-- Android >= 12 --> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <!-- Android < 12 --> <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" /> ...
With
neverForLocationflag active, you no longer need to ask forACCESS_FINE_LOCATIONin your app
To publish a new version of the package:
-
Ensure all tests pass:
pnpm test:package pnpm test:plugin
-
Commit your changes with a conventional commit message:
git add . git commit -m "fix: description of fix" git push origin master
-
Bump version in
package.json(follow semver):# Edit package.json to update version git add package.json git commit -m "chore: release X.Y.Z" git push origin master
-
Create and push git tag:
git tag vX.Y.Z -m "Release vX.Y.Z" git push origin vX.Y.Z -
Build and publish:
pnpm run prepack pnpm publish --access public --no-git-checks
Commit message conventions:
fix:- Bug fixes (patch version)feat:- New features (minor version)chore:- Maintenance tasksdocs:- Documentation updates
- Special thanks to @EvanBacon for supporting the expo config plugin.
