|
@@ -287,10 +287,16 @@ class bleManager {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ///连接设备
|
|
|
- var isAvailable = await that.openBluetoothAdapter();
|
|
|
- if (!isAvailable) {
|
|
|
- boolean(false);
|
|
|
+ ///做搜索蓝牙适配器权限
|
|
|
+ const permission_util = require('../utils/permission_util');
|
|
|
+ var available = await permission_util.openBluetoothAdapter();
|
|
|
+ that.isAvailable = available;
|
|
|
+ if (!available) {
|
|
|
+ that.doStartScaning = false;
|
|
|
+ that.requestBlueTime = that.getCurrentMills();
|
|
|
+ if (boolean != null) {
|
|
|
+ boolean(false);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -333,11 +339,9 @@ class bleManager {
|
|
|
|
|
|
wx.stopBluetoothDevicesDiscovery({
|
|
|
success: (res) => {
|
|
|
- console.log("停止搜索设备0", res);
|
|
|
that.search(connectWillDevice, boolean, callBackConnect);
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
- console.log("停止搜索设备1", err);
|
|
|
that.doStartScaning = false;
|
|
|
that.requestBlueTime = that.getCurrentMills();
|
|
|
if (boolean != null) {
|
|
@@ -347,52 +351,6 @@ class bleManager {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- ///打开蓝牙适配
|
|
|
- openBluetoothAdapter() {
|
|
|
- var that = this;
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- wx.openBluetoothAdapter({
|
|
|
- success: function (res) {
|
|
|
- that.isAvailable = res.available;
|
|
|
- console.log("sdfasdfadsf==00==" + that.isAvailable + "===" + JSON.stringify(res));
|
|
|
- resolve(that.isAvailable);
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- console.log("sdfasdfadsf==11==" + that.isAvailable + "===" + JSON.stringify(res));
|
|
|
- if (res.errno == 103) {
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
|
|
|
- showCancel: true,
|
|
|
- success: (modalRes) => {
|
|
|
- if (modalRes.confirm) {
|
|
|
- wx.openSetting({
|
|
|
- success: (settingRes) => {
|
|
|
- console.log("sdfasdfadsf==222==" + that.isAvailable + "===" + JSON.stringify(settingRes));
|
|
|
- if (settingRes.authSetting['scope.bluetooth']) {
|
|
|
- that.isAvailable = true;
|
|
|
- resolve(that.isAvailable);
|
|
|
- } else {
|
|
|
- that.isAvailable = false;
|
|
|
- resolve(that.isAvailable);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- } else if (modalRes.cancel) {
|
|
|
- that.isAvailable = false;
|
|
|
- resolve(that.isAvailable);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- that.isAvailable = false;
|
|
|
- resolve(that.isAvailable);
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
search(connectWillDevice, boolean, callBackConnect) {
|
|
|
var that = this;
|
|
|
wx.startBluetoothDevicesDiscovery({
|