startBluetoothDevicesDiscovery() {
var that = this;
if (this._discoveryStarted) {
this.stopBluetoothDevicesDiscovery()
return
}
this.setData({ misScanding: true,
scandbutName: "正在搜索,点击停止",
devices: [],
chs: [],
})
//console.log('lisn3188---------- misScanding = ', this.misScanding)
this._discoveryStarted = true
wx.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: (res) => {
setTimeout(function () {
console.log("----BluetoothDevicesDiscovery finish---- ");
if (that._discoveryStarted){
that.stopBluetoothDevicesDiscovery()
}
}, 20000);
console.log('startBluetoothDevicesDiscovery success', res)
this.onBluetoothDeviceFound()
},
})
},
stopBluetoothDevicesDiscovery() {
this._discoveryStarted = false
wx.stopBluetoothDevicesDiscovery()
this.setData({ misScanding: false, scandbutName:"重新刷新列表", })
//console.log('lisn3188---------- misScanding = ', this.misScanding)
},
onBluetoothDeviceFound() {
wx.onBluetoothDeviceFound((res) => {
res.devices.forEach(device => {
if (!device.name && !device.localName) {
return
}
const foundDevices = this.data.devices
const idx = inArray(foundDevices, 'deviceId', device.deviceId)
const data = {}
if (idx === -1) {
data[`devices[${foundDevices.length}]`] = device
} else {
data[`devices[${idx}]`] = device
}
this.setData(data)
})
})
},
体验版点击这个按钮可以搜索到蓝牙设备,发布后,点击没有任何反应了
