我想使用requestLEScan方法来扫描外围设备,但我找不到requestLEScan方法。 我在this doc
之后写了下面的内容<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title></title>
</head>
<body>
<button id="test" onclick="onButtonClick()">test</button>
<script>
function onButtonClick() {
navigator.bluetooth.requestLEScan({
filters: [{manufacturerData: {0x004C: {dataPrefix: new Uint8Array([
0x02, 0x15, // iBeacon identifier.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 // My beacon UUID.
])}}}],
options: {
keepRepeatedDevices: true,
}
}).then(() => {
navigator.bluetooth.addEventListener('advertisementreceived', event => {
let appleData = event.manufacturerData.get(0x004C);
if (appleData.byteLength != 23) {
// Isn’t an iBeacon.
return;
}
let major = appleData.getUint16(18, false);
let minor = appleData.getUint16(20, false);
let txPowerAt1m = -appleData.getInt8(22);
let pathLossVs1m = txPowerAt1m - event.rssi;
});
})
}
</script>
</body>
</html>
但它会导致这样的错误。
另外,我检查了对象,它只有requestDevice()方法
答案 0 :(得分:2)
根据WebBluetooth implementation status page,Chrome目前尚未实施requestLEScan
。您可以使用常规requestDevice
代替您的设备。