670人员登记调整,蓝牙成功不再走后端
This commit is contained in:
@ -453,7 +453,7 @@ class BleHelper {
|
||||
|
||||
uni.openBluetoothAdapter({
|
||||
success: (args) => {
|
||||
// console.log("蓝牙初始化成功:" + JSON.stringify(args));
|
||||
console.log("蓝牙初始化成功:" + JSON.stringify(args));
|
||||
this.data.isOpenBlue = true;
|
||||
this.data.available = true;
|
||||
resolve(true);
|
||||
@ -461,7 +461,7 @@ class BleHelper {
|
||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||
return;
|
||||
}
|
||||
// console.log("开始订阅各类变化消息");
|
||||
console.log("开始订阅各类变化消息");
|
||||
this.data.isSubscribe = true;
|
||||
|
||||
|
||||
@ -519,14 +519,29 @@ class BleHelper {
|
||||
}
|
||||
});
|
||||
|
||||
uni.onBluetoothDeviceFound((devices) => {
|
||||
uni.onBluetoothDeviceFound((res) => {
|
||||
// console.log("发现新设备:" + JSON.stringify(devices));
|
||||
let arr=[];
|
||||
for (var i = 0; i < res.devices.length; i++) {
|
||||
let item = res.devices[i];
|
||||
let f=serviceDic.find(v=>{
|
||||
return item.advertisServiceUUIDs.includes(v.serviceId);
|
||||
});
|
||||
if(f){
|
||||
arr.push(item);
|
||||
}
|
||||
|
||||
}
|
||||
if(arr.length===0){
|
||||
return;
|
||||
}
|
||||
res.devices=arr;
|
||||
this.data.searchList = this.data.searchList.concat(
|
||||
devices);
|
||||
res);
|
||||
if (this.cfg.onDeviceFound) {
|
||||
if (this.cfg.onDeviceFound.length > 0) {
|
||||
this.cfg.onDeviceFound.forEach((found) => {
|
||||
found.callback(devices);
|
||||
found.callback(res);
|
||||
});
|
||||
}
|
||||
|
||||
@ -779,19 +794,40 @@ class BleHelper {
|
||||
|
||||
//停止搜索
|
||||
StopSearch() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let p1= new Promise((resolve, reject) => {
|
||||
uni.stopBluetoothDevicesDiscovery({
|
||||
success: (res) => {
|
||||
//console.log("停止搜索蓝牙设备成功");
|
||||
console.log("停止搜索蓝牙设备成功");
|
||||
resolve();
|
||||
},
|
||||
fail: (ex) => {
|
||||
//console.log("无法停止蓝牙搜索");
|
||||
console.log("无法停止蓝牙搜索");
|
||||
|
||||
reject(this.getError(ex));
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
let p2 = new Promise((succ, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
|
||||
|
||||
return new Promise((resolve,reject)=>{
|
||||
Promise.race([p1,p2]).then(resolve).catch(ex=>{
|
||||
if (ex.code == -1) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
//获取已连接的设备
|
||||
|
||||
Reference in New Issue
Block a user