brycejacobs / react-native-ble-plx

React Native BLE library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-ble-plx

React Native Bluetooth Low Energy library using RxBluetoothKit and RxAndroidBle as it's backend libraries.

Example apps are available in Google Play and App Store!

GooglePlay AppStore


NPM


Recent Changes

0.5.0

  • Added new API for supporting unique Services and Characteristics:
    • Characteristic.id, Service.id fields which uniquely identify BLE objects.
    • All utility functions which don't require UUIDs as arguments are using internally id fields and therefore work faster and properly handle services/characteristics with same UUIDs. For example: characteristic.read().
  • New option to enable native modules' logging system via bleManager.setLogLevel() function.
  • New function to read RSSI for connected devices: bleManager.readRSSIForDevice().
  • Updated RxBluetoothKit dependency to version 3.0.12
  • Updated RxAndroidBle dependency to 1.2.2
  • Added tests for JS API.
  • Better Flow type checking and coverage.
  • Documentation was moved to ./docs folder and now is generated by documentation.js.
  • Small fixes in examples.
  • Updated installation steps.

All previous changes

Documentation

Documentation can be found here.

Configuration & Installation

Automatically

npm install --save react-native-ble-plx
react-native link

Both on iOS and Android continue manually from step 7.

Manually

iOS

  1. Add react-native-ble-plx to a project as a dependency in package.json file. For example "react-native-ble-plx": "Polidea/react-native-ble-plx" will install latest version from Polidea's Github repository.
  2. Make sure that you have Carthage installed on your system.
  3. Execute npm install to fetch and install a library.
  4. Open iOS project located in ./ios folder.
  5. Move BleClient.xcodeproj located in .node_modules/react-native-ble-plx/ios using drag & drop to Libraries folder in your project.
  6. In general settings of a target add libBleClient.a to Linked Frameworks and Libraries.
  7. In Build Settings/Search Paths/Framework search paths add path: $(SRCROOT)/../node_modules/react-native-ble-plx/ios/BleClientManager/Carthage/Build/iOS.
  8. In Build Settings/Build Options/Always Embed Swift Standard Libraries set to Yes.
  9. In Build Phases click on top left button and add New Run Script Phase.
  • Shell command: /usr/local/bin/carthage copy-frameworks
  • Input Files:
    • $(SRCROOT)/../node_modules/react-native-ble-plx/ios/BleClientManager/Carthage/Build/iOS/BleClientManager.framework
    • $(SRCROOT)/../node_modules/react-native-ble-plx/ios/BleClientManager/Carthage/Build/iOS/RxSwift.framework
    • $(SRCROOT)/../node_modules/react-native-ble-plx/ios/BleClientManager/Carthage/Build/iOS/RxBluetoothKit.framework
  1. Minimal supported version of iOS is 8.0

Android

  1. Add react-native-ble-plx to a project as a dependency in package.json file. For example "react-native-ble-plx": "Polidea/react-native-ble-plx" will install latest version from Polidea's Github repository.
  2. Execute npm install to fetch and install a library.
  3. Open Android project located in ./android folder.
  4. In settings.gradle add following lines:
include ':react-native-ble-plx'
project(':react-native-ble-plx').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ble-plx/android')
  1. In MainApplication.getPackages import and add BleModule package:
import com.polidea.reactnativeble.BlePackage;
...

public class MainApplication extends Application implements ReactApplication {
    ...

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new BlePackage()
      );
}
  1. In build.gradle of app module add following dependency:
dependencies {
   ...
   compile project(':react-native-ble-plx')
   ...
  1. Additionaly 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"
        ...

About

React Native BLE library

License:Apache License 2.0


Languages

Language:JavaScript 36.5%Language:Java 32.6%Language:Swift 20.9%Language:Objective-C 5.9%Language:Groovy 3.9%Language:Shell 0.2%