Events

Since react-native version 0.76, events are handled with specific methods that return the listener.

Examples

useEffect(() => {
  const onStopListener = BleManager.onStopScan((args) => {
    // Scanning is stopped args.status
  });

  return () => {
    onStopListener.remove();
  };
    
}, []);

onStopScan

The scanning for peripherals is ended.

Arguments


onDidUpdateState

The BLE change state.

Arguments

  • state - String - the new BLE state. can be one of unknown (iOS only), resetting (iOS only), unsupported, unauthorized (iOS only), on, off, turning_on (android only), turning_off (android only).

onDiscoverPeripheral

The scanning find a new peripheral.

Arguments

  • id - String - the id of the peripheral
  • name - String - the name of the peripheral
  • rssi - Number - the RSSI value
  • advertising - JSON - the advertising payload, here are some examples:
    • isConnectable - Boolean
    • serviceUUIDs - Array of String
    • manufacturerData - JSON - contains a json with the company id as field and the custom value as raw bytes and data (Base64 encoded string)
    • serviceData - JSON - contains the raw bytes and data (Base64 encoded string)
    • txPowerLevel - Int
    • rawData - [Android only] JSON - contains the raw bytes and data (Base64 encoded string) of the all advertising data

onDidUpdateValueForCharacteristic

A characteristic notify a new value.

Arguments

  • valueArray — the read value
  • peripheralString — the id of the peripheral
  • characteristicString — the UUID of the characteristic
  • serviceString — the UUID of the characteristic

Event will only be emitted after successful startNotification.


onConnectPeripheral

A peripheral was connected.

Arguments

  • peripheral - String - the id of the peripheral
  • status - Number - [Android only] connect reasons

onDisconnectPeripheral

A peripheral was disconnected.

Arguments


onPeripheralDidBond

A bond with a peripheral was established

Arguments

Object with information about the device


onCentralManagerWillRestoreState [iOS only]

This is fired when centralManager:WillRestoreState: is called (app relaunched in the background to handle a bluetooth event).

Arguments

  • peripherals - Array - an array of previously connected peripherals.

For more on performing long-term bluetooth actions in the background:

iOS Bluetooth State Preservation and Restoration

iOS Relaunch Conditions


onDidUpdateNotificationStateFor [iOS only]

The peripheral received a request to start or stop providing notifications for a specified characteristic’s value.

Arguments

  • peripheral - String - the id of the peripheral
  • characteristic - String - the UUID of the characteristic
  • isNotifying - Boolean - Is the characteristic notifying or not
  • domain - String - [iOS only] error domain
  • code - Number - [iOS only] error code

onCompanionPeripheral [Android only]

User picked a device to associate with.

Null if the request was cancelled by the user.

Arguments

  • id - String - the id of the peripheral
  • name - String - the name of the peripheral
  • rssi - Number - the RSSI value

onCompanionFailure [Android only]

Associate callback received a failure or failed to start the intent to pick the device to associate.