mtr1012 / react-native-ble-plx

React Native BLE library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-ble-plx

About this library

This is React Native Bluetooth Low Energy library using RxBluetoothKit and RxAndroidBle under the hood.

It supports:

What this library does NOT support:

Recent Changes

1.0.0

Breaking changes

  • Moved to Gradle plugin 3.1.4 and Gradle wrapper to 4.4 (RN 57+ required) on Android.

Other:

  • Added requestConnectionPriority function which increases or decreases connection interval setting on Android Lollipop devices or above.
  • Added connectionPriority option to connection options which calls above function just after the connection is established.
  • Added scanMode and callbackType properties to scan options for Android.
  • Added enable and disable functions to enable/disable Bluetooth on Android.
  • Added optional transactionId argument to discoverAllServicesAndCharacteristicsForDevice.
  • Added errorCodesToMessagesMapping property to BleManagerOptions to be able to override custom BleError messages.
  • Updated cancelDeviceConnection documentation.
  • Don't call CBCentralManager's stopScan, when Bluetooth is powered off in internal implementation on iOS.
  • Clean iOS compiler warnings on XCode10.
  • Changed scan record logging from Debug to Verbose on iOS.
  • Updated writeWithoutResponse implementation on iOS to use canSendWriteWithoutResponse if available starting from iOS 11.
  • Updated library's development dependencies.
  • Fixed cyclic import warnings.
  • Fixed notification/indication subscription moment. Events are monitored before CCC is written on Android.

All previous changes

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)

  1. npm install --save react-native-ble-plx
  2. react-native link react-native-ble-plx
  3. 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.
  4. Minimal supported version of iOS is 8.0
  5. If you want to support background mode:
    • In your application target go to Capabilities tab and enable Uses Bluetooth LE Accessories in Background Modes section.
    • Pass restoreStateIdentifier and restoreStateFunction to BleManager constructor.

iOS (expo/Podfile, example setup)

  1. Make sure your Expo project is detached. You can read how to do it here and here.
  2. npm install --save react-native-ble-plx
  3. react-native link react-native-ble-plx
  4. 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.
  5. 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'
    
  6. Enter ios folder and run pod update
  7. Minimal supported version of iOS is 8.0
  8. If you want to support background mode:
    • In your application target go to Capabilities tab and enable Uses Bluetooth LE Accessories in Background Modes section.
    • Pass restoreStateIdentifier and restoreStateFunction to BleManager constructor.

Android (example setup)

  1. npm install --save react-native-ble-plx
  2. react-native link react-native-ble-plx
  3. In build.gradle of app module make sure that min SDK version is at least 18:
android {
    ...
    defaultConfig {
        minSdkVersion 18
        ...
  1. 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.**

About

React Native BLE library

License:Apache License 2.0


Languages

Language:Swift 77.4%Language:Java 10.4%Language:JavaScript 9.5%Language:Objective-C 1.7%Language:Groovy 0.9%Language:Ruby 0.1%Language:C 0.0%