BluetoothCharacteristicProperties
BluetoothCharacteristicProperties 接口是 Web Bluetooth API 的一部分,它提供了在给定的 BluetoothRemoteGATTCharacteristic 上有效的操作。
通过调用 BluetoothRemoteGATTCharacteristic.properties 来返回此接口。
实例属性
authenticatedSignedWrites只读 实验性-
返回一个
boolean值,如果允许对特性值进行签名写入,则为true。 broadcast只读 实验性-
返回一个
boolean值,如果允许使用服务器特性配置描述符广播特性值,则为true。 indicate只读 实验性-
返回一个
boolean值,如果允许带有确认的特性值指示,则为true。 notify只读 实验性-
返回一个
boolean值,如果允许不带确认的特性值通知,则为true。 read只读 实验性-
返回一个
boolean值,如果允许读取特性值,则为true。 reliableWrite只读 实验性-
返回一个
boolean值,如果允许对特性进行可靠写入,则为true。 writableAuxiliaries只读 实验性-
返回一个
boolean值,如果允许对特性的描述符进行可靠写入,则为true。 write只读 实验性-
返回一个
boolean值,如果允许带有响应的特性写入,则为true。 writeWithoutResponse只读 实验性-
返回一个
boolean值,如果允许不带响应的特性写入,则为true。
示例
以下示例展示了如何检查 GATT 特性是否支持值更改通知。
js
let device = await navigator.bluetooth.requestDevice({
filters: [{ services: ["heart_rate"] }],
});
let gatt = await device.gatt.connect();
let service = await gatt.getPrimaryService("heart_rate");
let characteristic = await service.getCharacteristic("heart_rate_measurement");
if (characteristic.properties.notify) {
characteristic.addEventListener(
"characteristicvaluechanged",
async (event) => {
console.log(`Received heart rate measurement: ${event.target.value}`);
},
);
await characteristic.startNotifications();
}
规范
| 规范 |
|---|
| Web 蓝牙 # characteristicproperties-interface |
浏览器兼容性
加载中…