收藏
回答

在onShow()中开启蓝牙扫描会搜不出设备?

在页面的onShow函数中, 打开蓝牙适配器 , 开启扫描, 在部分手机会出现搜不到设备或者搜到一个设备后再也不会搜到设备的情况

如果扫描是通过点击按钮开始的话, 表现又是正常的

已经设置了allowDuplicate为true, 在小米4c, 5上有这个问题, iOS表现正常

onShow(){
    this.startblue()
  },
 
 
  //蓝牙状态
  startblue: function () {
    var that = this;
    //初始化蓝牙模块
    wx.openBluetoothAdapter({
      success: (res) => {
        wx.startBluetoothDevicesDiscovery({
          interval: 500,
          allowDuplicatesKey: true,
          success: (res) => {
            wx.onBluetoothDeviceFound((res) => {
              console.log(res.devices)
            })
          },
          fail: (res) => {
 
          }
        })
      },
      fail: (res) => {
        console.log(res)
        wx.showModal({
          content: '请先开启手机蓝牙'
        })
      }
    })
 
  },


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签