开发者工具微信基础库 3.02 调试手机IOS12,
相关代码片段:
var devices = [];
wx.openBluetoothAdapter({
success: function (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'],
success: function (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({
success: function () {
}
})
}
})
}, fail:function (res) {
//先关闭搜索再重新开启搜索,这一步操作是防止重复wx.startBeaconDiscovery导致失败
console.log("蓝牙信标搜索失败" + res.beacons);
console.log(res.beacons);
stopSearchBeacon();
}
})
setTimeout(function () {
wx.stopBeaconDiscovery({
success: function () {
console.log("停止设备扫描!");
console.log(devices);
}
});
}, 20* 1000);
调试结果:
没有执行 wx.onBeaconUpdate()