rn-ble-pic
v0.2.2
Published
A complete Bluetooth Low Energy (BLE) module for react native applications.
Readme
rn-ble-pic
Pre-requisites
Android API >= 21 IOS >= 10.0 ReactNative >= 0.50
Getting started
$ npm install rn-ble-pic --save
Mostly automatic installation
$ react-native link rn-ble-pic
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜rn-ble-picand addRNBlePic.xcodeproj - In XCode, in the project navigator, select your project. Add
libRNBlePic.ato your project'sBuild Phases➜Link Binary With Libraries - Run your project (
Cmd+R)
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.blepic.RNBlePicPackage;to the imports at the top of the file - Add
new RNBlePicPackage()to the list returned by thegetPackages()method
- Append the following lines to
android/settings.gradle:include ':rn-ble-pic' project(':rn-ble-pic').projectDir = new File(rootProject.projectDir, '../node_modules/rn-ble-pic/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle:compile project(':rn-ble-pic')
Usage
// get an instance of BLEPIC module
import BLEPIC from "rn-ble-pic";
// add peripheral name
BLEPIC.setPeripheralName(name: string);
// add services
BLEPIC.addService(serviceUUID: string, primary: boolean, serviceData: string);
// add characteristics to a service
BLEPIC.addCharacteristicToService(serviceUUID: string, charUUID: string, permissions: int, properties: int, data: string);
// start advertising
BLEPIC.startAdvertising();
// check if currently advertising or not
BLEPIC.isAdvertising();
// stop advertising
BLEPIC.stopAdvertising();