title: Taro.onBLEConnectionStateChange(callback)

sidebar_label: onBLEConnectionStateChange

Listens on the BLE connection status change event, including connections manually established or disconnected by developers, device loss, and unusual disconnections.

Reference

Type

  1. (callback: Callback) => void

Parameters

CallbackResult

Property Type Description
connected boolean Indicates whether the device is connected
deviceId string The Bluetooth device ID

Callback

The callback function for the BLE connection status change event.

  1. (result: CallbackResult) => void
Property Type
result CallbackResult

Sample Code

  1. Taro.onBLEConnectionStateChange(function (res) {
  2. // You can use the callback for this method to handle accidental disconnects and other exceptions.
  3. console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
  4. })

API Support

API WeChat Mini-Program H5 React Native
Taro.onBLEConnectionStateChange ✔️