wx.getBluetoothDevices返回的name是“未知设备”
发布于 6 年前 作者 qma 9122 次浏览 来自 问答

现象如下:

用下面的代码,在从来没有扫描过本小程序的iOS上,扫描进入,调用对应代码,会打印出一系列的:

             扫到的:未知设备

              扫到的:未知设备

              扫到的:未知设备

              扫到的:未知设备

而关闭系统蓝牙再打开,再扫,还是如此。

而将微信后台清掉,再进入微信,进入本小程序,再扫,每个设备的名字就准确的扫描出来了。之后,就都能准确扫到了。

使用新的iOS手机能复现。

代码片段如下:

wx.startBluetoothDevicesDiscovery({

      services: [‘FFE5’], // 只搜索含有FFE5主服务的uuid

      allowDuplicatesKey: false,

      interval: 100,

      success: function (res) {

        console.log(‘开启BLE发现服务成功’)

        that.DeviceScanInterval(operType)

      },

      fail: function (res) {

      }

    })

  DeviceScanInterval: function (operType) {

      wx.getBluetoothDevices({

        success: function (res) {

          console.log(‘在寻找设备:’ + that.data.DeviceId)

          that.data.signalStrength = 0

          var i = 0

          for (; i < res.devices.length; i++) {

            console.log(‘扫到的:’ + res.devices[i].name)

            if (res.devices[i].name == that.data.DeviceId) {

              console.log(‘已搜索到指定设备’)

              //-------------停止蓝牙BLE扫描------------------

              wx.stopBluetoothDevicesDiscovery({

                complete: function () {

                  }

                },

              })

              break

            }

          }

        },

        fail: function (res) {

          console.log(res)

          that.data.signalStrength = 0

        },

      })

}

1 回复

你好这问题解决了没有,还有就是有时候名字为空,什么都不显示

回到顶部