跳至主要內容

HTMLBluetoothElement.requestAndConnectDevice()

BFChainWebComponentHTMLBluetoothElementrequestAndConnectDevice小于 1 分钟

打开蓝牙设备;内部实际调用的是 BluetoothPlugin.requestAndConnectDevice()方法

HTMLBluetoothElement.requestAndConnectDevice(options)

参数

返回值

返回一个Promise, resolve兑现一个实现了BluetoothRequestAndConnectDeviceResponse接口的对象;

示例

<body>
  <dweb-bluetooth></dweb-bluetooth>
  <button>open</button>
  <script type="module">
    import "@plaoc/plugins"
    const bluetooth = document.querySelector("dweb-bluetooth")!
    const btn = document.querySelector('button');
    btn.addEventListener('click', async () => {
      bluetooth
      .open()
      .then(res => {
        if(res.success){
          const options = {
            acceptAllDevices: true,
            optionalServices: ["00003802-0000-1000-8000-00805f9b34fb"],
          }
          return bluetoothPlugin.requestAndConnectDevice(options)
        }
      })
      .then(res => {
        if(res.success){
          // 成功的查询和连接了蓝牙设备;
        }
      })
    })
  </script>
</body>

平台兼容性

属性/方法/事件AndroidIOSDesktop-DevDesktop
requestAndConnectDeviceX

相关链接

HTMLBluetoothElement

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.7