修复蓝牙同步问题
This commit is contained in:
@ -630,20 +630,38 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.data.isOpenBlue) {
|
const runInit = () => {
|
||||||
|
this.CheckBlue().then((res) => {
|
||||||
|
return init();
|
||||||
|
}).then(resolve).catch((ex) => {
|
||||||
|
console.error("异常:", ex);
|
||||||
|
reject(ex);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (!this.data.isOpenBlue) {
|
||||||
|
runInit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 已打开过仍须向系统确认可用:关蓝牙再开后 isOpenBlue 可能未及时被置 false,或状态回调未送达
|
||||||
|
if (typeof uni.getBluetoothAdapterState !== 'function') {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
uni.getBluetoothAdapterState({
|
||||||
this.CheckBlue().then((res) => {
|
success: (info) => {
|
||||||
// console.log("res=", res)
|
this.data.available = !!info.available;
|
||||||
return init();
|
if (info.available) {
|
||||||
}).then(resolve).catch((ex) => {
|
resolve();
|
||||||
console.error("异常:", ex);
|
return;
|
||||||
reject(ex);
|
}
|
||||||
|
this.data.isOpenBlue = false;
|
||||||
|
runInit();
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
this.data.isOpenBlue = false;
|
||||||
|
runInit();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -865,6 +883,9 @@ class BleHelper {
|
|||||||
|
|
||||||
|
|
||||||
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
if (!state.available) { //蓝牙状态不可用了,将所有设备标记为断开连接
|
||||||
|
// 系统关蓝牙后原生 BLE 适配器已销毁;若仍认为 isOpenBlue=true,OpenBlue 会跳过重开,
|
||||||
|
// 再开蓝牙后无法 createBLEConnection / 一直报 10001 适配器不可用
|
||||||
|
this.data.isOpenBlue = false;
|
||||||
console.log("蓝牙模块不可用了,将所有设备标记为断开连接");
|
console.log("蓝牙模块不可用了,将所有设备标记为断开连接");
|
||||||
this.data.connectingDevices = {}; //清空连接锁
|
this.data.connectingDevices = {}; //清空连接锁
|
||||||
this.data.LinkedList.filter((v) => {
|
this.data.LinkedList.filter((v) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user