收藏
回答

蓝牙api用朋友的手机点击五次确定以后就不搜索了?

流程是这样的:搜索到设备关闭搜索关闭蓝牙连接然后弹框,点击确定以后继续调用这个方法开启搜索,我的两个手机测试的都没问题,朋友的手机点五次弹框以后就不搜索了,这是什么bug

代码片段:

lanya() {
    let that = this
    wx.openBluetoothAdapter({
      successfunction (res{
        console.log(res)
        //开始搜索蓝牙
        wx.startBluetoothDevicesDiscovery({
          successfunction (res{
            console.log('search', res)
            wx.onBluetoothDeviceFound(function (devices{
              console.log('发现设备22', devices.devices)
              for (let i = 0; i < devices.devices.length; i++) {
                if (!(undefined == devices.devices[i].localName)) {
                  //检索指定设备
                  if (devices.devices[i].localName.split('-')[0] == 'HRC') {
                    console.log('已找到指定设备:', devices.devices[i].localName);
                    //关闭搜索
                    wx.stopBluetoothDevicesDiscovery({
                      success (res) {
                        console.log('关闭搜索',res)
                      }
                    });
                    //关闭蓝牙连接
                    wx.closeBluetoothAdapter({
                      successfunction (res{
                        console.log('关闭蓝牙连接',res)
                      }
                    });
                    wx.showModal({
                      title'提示',
                      content'发现设备:' + devices.devices[i].localName,
                      showCancelfalse,
                      successfunction (res{
                        if (res.confirm) {
                          console.log('用户点击确定')
                          that.lanya()
                        }
                      }
                    })
                    break;
                  }
                }
              }
            })
          }
        })
      },
      failfunction (res{
        wx.showModal({
          showCancelfalse,
          content'请先开启手机蓝牙',
          successfunction (res{
            setTimeout(function () {
              that.lanya()
            }, 5000)
          }
        })
      }
    })
  }



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

1 个回答

  • 疯狂的小辣椒
    疯狂的小辣椒
    2020-05-07

    你好,打印一下complete或者fail回调排查下。

    2020-05-07
    有用
    回复 6
    • CX330
      CX330
      2020-05-08
      不调用失败回调函数,的第六次就反正就是第六次就不搜索了
      2020-05-08
      回复
    • 疯狂的小辣椒
      疯狂的小辣椒
      2020-05-08回复CX330
      麻烦具体描述问题流程,提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
      2020-05-08
      回复
    • CX330
      CX330
      2020-05-08回复疯狂的小辣椒
      流程:搜索到指定设备关闭搜索关闭蓝牙连接弹框,点击确定以后继续调用该方法,前五次正常,第六次点击确定以后就不搜索了
      问题机型:oppoR17 华为mate20
      微信版本号:7.0.14
      系统版本号:Android9(oppoR17)  华为mate20的系统不清楚
      代码片段:https://developers.weixin.qq.com/s/tJCGwbmX7th5
      2020-05-08
      回复
    • 疯狂的小辣椒
      疯狂的小辣椒
      2020-05-08回复CX330
      这个代码片段,开启蓝牙之后,关闭弹窗,已经不再执行了呀,你是怎么重复操作的呢?
      2020-05-08
      回复
    • CX330
      CX330
      2020-05-09回复疯狂的小辣椒
      关闭弹窗以后that.lanya()调用本方法
      2020-05-09
      回复
    查看更多(1)
登录 后发表内容
问题标签