小程序调用蓝牙API问题
发布于 5 年前 作者 lixiulan 15111 次浏览 来自 问答
  wx.openBluetoothAdapter({
      success: function (res) {
        that.setData({
          msg: "初始化蓝牙适配器成功!" + JSON.stringify(res),
        })
        //监听蓝牙适配器状态  
        wx.onBluetoothAdapterStateChange(function (res) {
          that.setData({
            sousuo: res.discovering ? "在搜索。" : "未搜索。",
            status: res.available ? "可用。" : "不可用。",
          })
        })
      },
      complete: function (res) {
        // complete
        console.log(res);
      }
    })

这段代码,执行到了complete,输出内容为
{errMsg: "openBluetoothAdapter:fail TypeError: Cannot read property 'addListener' of undefined"}errMsg: "openBluetoothAdapter:fail TypeError: Cannot read property 'addListener' of undefined"__proto__: Object



网上查了下,并没类似的资料,有人碰到类似问题,说是一样的代码在之前的开发者工具调试就不会出这个问题?
2 回复

用的新版开发者工具吗?貌似还不支持蓝牙调试,你真机试试应该没问题  

 

                                                                                                                             答案来至于——咫尺开发论坛

你好,是否用的是新版的开发者工具呢? 新版本开发者工具目前无法使用蓝牙SDK

https://developers.weixin.qq.com/blogdetail?action=get_post_info&lang=zh_CN&token=1653444143&docid=8f3ae006e9459bdf7f31fb5d7c73e235

建议直接用真机调试。

回到顶部