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.onBLECharacteristicValueChange callback.
  • On the Android platform, if the writeBLECharacteristicValue API is called right after the call to notifyBLECharacteristicValueChange, some device models will report a 10008 system error.

Reference

Type

  1. (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

  1. Taro.notifyBLECharacteristicValueChange({
  2. state: true, // Enable the notify feature
  3. // This deviceId must have been used to connect the appropriate device via createBLEConnection.
  4. deviceId,
  5. // This serviceId must be obtained in the getBLEDeviceServices API.
  6. serviceId,
  7. // This characteristicId must be obtained in the getBLEDeviceCharacteristics API.
  8. characteristicId,
  9. success: function (res) {
  10. console.log('notifyBLECharacteristicValueChange success', res.errMsg)
  11. }
  12. })

API Support

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