title: Taro.notifyBLECharacteristicValueChange(option)
sidebar_label: notifyBLECharacteristicValueChange
Enables the notify feature when characteristics of a BLE device change to subscribe to characteristics. Note: The device characteristics must support notify or indicate to use this method.
In addition, you must enable notifyBLECharacteristicValueChange to listen on the device characteristicValueChange event.
Notes
- After a successful subscription, the device must actively update the value of the characteristic to trigger the
Taro.onBLECharacteristicValueChangecallback. - On the Android platform, if the
writeBLECharacteristicValueAPI is called right after the call tonotifyBLECharacteristicValueChange, some device models will report a 10008 system error.
Type
(option: Option) => Promise<Promised>
Parameters
Promised
| Property | Type | Description |
|---|---|---|
| errMsg | string |
success: ok,fail: error message |
Option
| Property | Type | Required | Description |
|---|---|---|---|
| characteristicId | string |
Yes | The Bluetooth characteristic UUID |
| deviceId | string |
Yes | The Bluetooth device ID |
| serviceId | string |
Yes | The UUID of the service corresponding to a Bluetooth characteristic |
| state | boolean |
Yes | Indicates whether notify is enabled |
| complete | (res: any) => void |
No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail | (res: any) => void |
No | The callback function for a failed API call |
| success | (res: Result) => void |
No | The callback function for a successful API call |
Sample Code
Taro.notifyBLECharacteristicValueChange({state: true, // Enable the notify feature// This deviceId must have been used to connect the appropriate device via createBLEConnection.deviceId,// This serviceId must be obtained in the getBLEDeviceServices API.serviceId,// This characteristicId must be obtained in the getBLEDeviceCharacteristics API.characteristicId,success: function (res) {console.log('notifyBLECharacteristicValueChange success', res.errMsg)}})
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.notifyBLECharacteristicValueChange | ✔️ |
