使用navigator.bluetooth.requestDevice()
,我可以访问已经使用本机 OSX 蓝牙配对设置配对的蓝牙设备,但没有出现以前未配对的设备,即使它们的属性与我的通用查询匹配。可用设备以 Chrome 模式显示,请求用户同意配对,但唯一显示的设备是我已经配对的设备。
我在这里误解了预期的用例,还是有另一种方法可以从 Chrome 与附近的(以前未配对的)设备建立连接?
文档:https ://webbluetoothcg.github.io/web-bluetooth/ (参见示例 2)
function bluetoothConnect() {
navigator.bluetooth.requestDevice({filters: [{services: ['generic_access']}]})
.then(device => {console.log(`Connected to: ${device.name}`)})
.catch(console.error);
}