HarmonyOS Ble疑问?

if (this.singleCapsuleSelectedIndexes[0] == 0) {
  this.gattClient.setCharacteristicChangeNotification(characteristic, isOn)
} else {
  this.gattClient.setCharacteristicChangeIndication(characteristic, isOn);
}

上面这两个方法有什么区分,在订阅特征值时,不调用这个方法,是否可以读取特征值及描述,及订阅特征值?

阅读 568
1 个回答

setCharacteristicChangeIndication和setCharacteristicChangeNotification都是向服务端发送设置通知此特征值请求,不同在于,setCharacteristicChangeIndication需要对端服务回复,且后面发送特征值请求给对端时,对端不会回复。

由于on(type: ‘BLECharacteristicChange’)订阅接口需要调用setCharacteristicChangeNotification接口,若是不使用setCharacteristicChangeNotification的话,无法订阅特征值。若是客户端主动读取服务端特征值和描述符的话,可以使用readCharacteristicValue和readDescriptorValue接口。

ble官方文档如下:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-bluetooth-ble-V5

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进