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.
Type
(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.
(result: CallbackResult) => void
Property | Type |
---|---|
result | CallbackResult |
Sample Code
Taro.onBLEConnectionStateChange(function (res) {
// You can use the callback for this method to handle accidental disconnects and other exceptions.
console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.onBLEConnectionStateChange | ✔️ |