修复有时候蓝牙配对成功依然提示未连接的异常
This commit is contained in:
@ -122,7 +122,7 @@ class BleHelper {
|
||||
{
|
||||
key: '10013',
|
||||
remark: '连接 deviceId 为空或者是格式不正确'
|
||||
},
|
||||
},
|
||||
{
|
||||
key: '10016',
|
||||
remark: '定位服务已关闭'
|
||||
@ -164,7 +164,20 @@ class BleHelper {
|
||||
//更新缓存
|
||||
updateCache() {
|
||||
|
||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||
let task =async () => {
|
||||
await uni.setStorage({
|
||||
key: this.StorageKey,
|
||||
data: this.data.LinkedList,
|
||||
success() {
|
||||
|
||||
},
|
||||
fail(ex) {
|
||||
console.error("更新蓝牙缓存失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
task();
|
||||
|
||||
}
|
||||
//连接所有已连接过的设备
|
||||
@ -1595,7 +1608,7 @@ class BleHelper {
|
||||
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId, maxRetries) {
|
||||
|
||||
//连接成功的回调
|
||||
let LinkedCallback=() => {
|
||||
let LinkedCallback = () => {
|
||||
if (this.cfg.recoveryCallback.length > 0) {
|
||||
this.cfg.recoveryCallback.forEach((
|
||||
c) => {
|
||||
@ -1667,7 +1680,7 @@ class BleHelper {
|
||||
console.log("当前已连接,释放连接锁");
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
resolve(false);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1689,7 +1702,7 @@ class BleHelper {
|
||||
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
console.error("新连接成功释放连接锁", deviceId);
|
||||
|
||||
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
this.setMtu(deviceId).catch(ex => {
|
||||
@ -1703,7 +1716,7 @@ class BleHelper {
|
||||
if (c.deviceId == deviceId) {
|
||||
c.Linked = true;
|
||||
c.linkId = linkId
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -1711,9 +1724,11 @@ class BleHelper {
|
||||
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
this.data.LinkedList[fIndex].linkId =linkId;
|
||||
this.data.LinkedList[fIndex].name =cr.name;
|
||||
this.data.LinkedList[fIndex].advertisData =cr.advertisData;
|
||||
this.data.LinkedList[fIndex].linkId =
|
||||
linkId;
|
||||
this.data.LinkedList[fIndex].name = cr.name;
|
||||
this.data.LinkedList[fIndex].advertisData =
|
||||
cr.advertisData;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
@ -1727,7 +1742,7 @@ class BleHelper {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
resolve(true);
|
||||
|
||||
}).catch((ex) => {
|
||||
@ -1735,7 +1750,7 @@ class BleHelper {
|
||||
});
|
||||
},
|
||||
fail: (ex) => {
|
||||
if(ex.code===10010){
|
||||
if (ex.code === 10010) {
|
||||
console.log("设备已连接,无需重复连接");
|
||||
delete this.data.connectingDevices[deviceId];
|
||||
resolve(true);
|
||||
@ -1775,7 +1790,7 @@ class BleHelper {
|
||||
console.log("2222222");
|
||||
return linkDevice(deviceId);
|
||||
}).then((res) => {
|
||||
LinkedCallback();
|
||||
LinkedCallback();
|
||||
if (res) { //新连接(含 createBLEConnection 刚成功)
|
||||
// console.log("11111111");
|
||||
if (fIndex == -1) {
|
||||
|
||||
Reference in New Issue
Block a user