Selaa lähdekoodia

feature: 解决类数据丢失的问题

332777428@qq.com 6 kuukautta sitten
vanhempi
commit
f7c8aaa7bf
2 muutettua tiedostoa jossa 37 lisäystä ja 1 poistoa
  1. 1 1
      devices/ble_manager.js
  2. 36 0
      utils/permission_util.js

+ 1 - 1
devices/ble_manager.js

@@ -271,7 +271,7 @@ class bleManager {
       }
 
       ///做搜索蓝牙适配器权限
-      const permission_util = require('../utils/permission_util');
+      const permission_util = require('./../utils/permission_util');
       var available = await permission_util.openBluetoothAdapter();
       that.isAvailable = available;
       if (!available) {

+ 36 - 0
utils/permission_util.js

@@ -0,0 +1,36 @@
+module.exports = {
+  openBluetoothAdapter: openBluetoothAdapter,
+}
+
+// 打开蓝牙权限
+function openBluetoothAdapter() {
+  return new Promise((resolve, reject) => {
+    wx.openBluetoothAdapter({
+      success: function (res) {
+        resolve(true);
+      },
+      fail: function (res) {
+        if (res.errno == 103) {
+          wx.showModal({
+            title: '提示',
+            content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
+            showCancel: true,
+            success: (modalRes) => {
+              if (modalRes.confirm) {
+                wx.openSetting({
+                  success: (settingRes) => {
+                    resolve(settingRes.authSetting['scope.bluetooth'] ? true : false);
+                  }
+                });
+              } else if (modalRes.cancel) {
+                resolve(false);
+              }
+            }
+          });
+        } else {
+          resolve(false);
+        }
+      }
+    })
+  });
+}