Socket
Socket
Sign inDemoInstall

react-native-ble-manager

Package Overview
Dependencies
0
Maintainers
1
Versions
159
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-ble-manager

A BLE module for react native.


Version published
Weekly downloads
49K
decreased by-20.79%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-native-ble-manager

npm version npm downloads

This is a porting of https://github.com/don/cordova-plugin-ble-central project to React Native.

##Supported Platforms

  • iOS
  • Android (API 16)

##Install

npm i --save react-native-ble-manager

####iOS

  • Open the node_modules/react-native-ble-manager/ios folder and drag BleManager.xcodeproj into your Libraries group.
  • Check the "Build Phases"of your project and add "libBleManager.a" in the "Link Binary With Libraries" section.

####Android #####Update Gradle Settings

// file: android/settings.gradle
...

include ':react-native-ble-manager'
project(':react-native-ble-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ble-manager/android')

#####Update Gradle Build

// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':react-native-ble-manager')
}

#####Register React Package

...
import it.innove.BleManagerPackage; // <--- import

public class MainActivity extends ReactActivity {

    ...

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new BleManagerPackage(this) // <------ add the package
        );
    }

    ...
}

##Methods

scan(serviceUUIDs, seconds)

Scan for availables peripherals. Returns a Promise object.

Arguments

  • serviceUUIDs - Array of String - the UUIDs of the services to looking for.
  • seconds - Integer - the amount of seconds to scan.

Examples

BleManager.scan([])
  .then(() => {
    // Success code
    console.log('Scan started');
  });
  

connect(peripheralId)

Attempts to connect to a peripheral. Returns a Promise object.

Arguments

  • peripheralId - String - the id/mac address of the peripheral to connect.

Examples

BleManager.connect('4B28EF69-423D-FA86-01FA-CC6CB923A2C9')
  .then(() => {
    // Success code
    console.log('Connected');
  })
  .catch((error) => {
    // Failure code
    console.log(error);
  });

disconnect(peripheralId)

Disconnect from a peripheral. Returns a Promise object.

Arguments

  • peripheralId - String - the id/mac address of the peripheral to disconnect.

Examples

BleManager.disconnect('4B28EF69-423D-FA86-01FA-CC6CB923A2C9')
  .then(() => {
    // Success code
    console.log('Connected');
  })
  .catch((error) => {
    // Failure code
    console.log(error);
  });

##Events

BleManagerStopScan

The scanning for peripherals is ended.

Arguments

  • none

BleManagerDidUpdateState

The BLE change state.

BleManagerDiscoverPeripheral

BleManagerDidUpdateValueForCharacteristic

BleManagerDisconnectPeripheral

Keywords

FAQs

Last updated on 26 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc