let self = this;
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: res => {
console.log('startBluetoothDevicesDiscovery')
setTimeout(()=>{
uni.onBluetoothDeviceFound(devices => {
console.log('onBluetoothDeviceFound')
console.log(JSON.stringify(devices))
console.log("发现新设备: " + JSON.stringify(devices));
if (devices.devices[0].name != "") {
//不重复,就添加到devicesList中,
if (!self.devicesList.some(item => {
return item.deviceId === devices.devices[0].deviceId
})) {
self.devicesList.push(devices.devices[0])
}
}
self.devicesList.sort(function(a, b) {
if (a.deviceId === _this.connectDevice.deviceId) {
return -1;
} else if (b.deviceId === _this.connectDevice.deviceId) {
return 1;
} else {
return 0;
}
})
})
},2000)
},
fail: err => {
console.log(err)
self.isOpenBle = false
self.isSearch = false
// uni.hideLoading();
// bluetooth.showToast(`搜索设备失败` + JSON.stringify(err));
}
})
9***@qq.com (作者)
调过了,代码没贴进去
2023-12-01 15:24