Przeglądaj źródła

feature: 处理断开蓝牙连接异常的问题

Damon 7 miesięcy temu
rodzic
commit
4f39692013
1 zmienionych plików z 16 dodań i 7 usunięć
  1. 16 7
      devices/ble_manager.js

+ 16 - 7
devices/ble_manager.js

@@ -337,16 +337,25 @@ class bleManager {
     }
 
     return new Promise((resolve, reject) => {
-      wx.closeBLEConnection({
-        deviceId: deviceId,
+      wx.getConnectedBluetoothDevices({
         success: (res) => {
-          that.publicDevice = null;
-          console.log('断开连接成功:', res);
-          resolve(res);
+          if (res.devices.length > 0) {
+            wx.closeBLEConnection({
+              deviceId: deviceId,
+              success: (res) => {
+                that.publicDevice = null;
+                resolve(res);
+              },
+              fail: (err) => {
+                resolve(err);
+              }
+            });
+          } else {
+            resolve(err);
+          }
         },
         fail: (err) => {
-          console.error('断开连接失败:', err);
-          reject(new Error('断开连接失败'));
+          resolve(err);
         }
       });
     });