收藏
回答

获取信标信息, wx.OnBeaconUpdate不执行?

开发者工具微信基础库 3.02 调试手机IOS12,

相关代码片段:

var devices = [];
      wx.openBluetoothAdapter({
        successfunction (res{
          that.setData({ INFO"蓝牙已经打开" });
          console.log("蓝牙已经打开");
          console.log("开始启动搜索信标")
          // 搜索蓝牙信标
          wx.startBeaconDiscovery({ //搜索附近的iBeacon设备
            //uuids: ['74278adb-b644-4520-8f0c-720eaf059935'],//uuid参数
            //uuids:['00001803-494c-4f47-4943-544543480000','00001805-494c-4f47-4943-544543480000','00001804-494c-4f47-4943-544543480000'],//uuid参数
            uuids:['00001803-494c-4f47-4943-544543480000'],
            successfunction (res{
                console.log("开始扫描设备..."+ res.errMsg +"Code:"+res.errCode);  
              //控制台打印 
             /*
              wx.getBeacons({
                success(res) {
                  console.log(res)
                }
              })*/
              wx.onBeaconUpdate(function(res2){
                console.log("打印监听到的设备信息" + res2.beacons);
                console.log(res2.beacons);
                var beacons = res2.beacons;
                var reqContent = {};
                var bleArray = [];
                console.log(res2.beacons);
                if (res2 && res2.beacons && res2.beacons.length > 0) {
                    devices = res2.beacons;
                }
                if(res2.beacons.accuracy != -1){
                  wx.stopBeaconDiscovery({
                    successfunction () {
                    }
                  })
                }
              })
            }, fail:function (res{
                //先关闭搜索再重新开启搜索,这一步操作是防止重复wx.startBeaconDiscovery导致失败
                console.log("蓝牙信标搜索失败" + res.beacons);
                console.log(res.beacons);
                stopSearchBeacon();
              }
        })
        setTimeout(function () {
            wx.stopBeaconDiscovery({
                successfunction () {
                   
                    console.log("停止设备扫描!");
                    console.log(devices);
                }
            });
        }, 201000);

调试结果:

没有执行  wx.onBeaconUpdate()


回答关注问题邀请回答
收藏
登录 后发表内容