注意:这里获取的是蓝牙信标,而不是蓝牙设备
wx.request({ url: 'https://travel.kuxia.top/api/device/index', data: { id: 2 }, method: 'GET', success: (res) => { console.log(res); let BeaconData = res.data.data let seach = {} let uuids = [] for (let i = 0; i < res.data.data.length; i++) { uuids.push(res.data.data[i].deviceid) } console.log(uuids); // 初始化蓝牙设备 wx.openBluetoothAdapter({ success: function (blueres) { console.log('蓝牙适配器初始化成功', blueres) wx.startBeaconDiscovery({ uuids: uuids, //多个uuid数组 success: function (res) { console.log(res); wx.onBeaconUpdate(function () { //设置监听事件 wx.getBeacons({ //在监听事件中获取数据 success: res => { console.log(res.beacons) //res.beacons 为搜索到的iBeacon数据数组 //业务代码 for (let i = 0; i < BeaconData.length; i++) { console.log(res.beacons[0].uuid); console.log(BeaconData[i].deviceid); if (res.beacons[0].uuid.toUpperCase() == BeaconData[i].deviceid.toUpperCase()) { console.log(123); } } console.log(seach); wx.stopBeaconDiscovery({ success(res) { console.log("已暂停搜索", res); } }) } }) }) } }) }, fail: function (res) { console.log('蓝牙适配器初始化失败', res) } }) } })