1
0
forked from dyf/APP

修改蓝牙发现逻辑自动连接过的不再被发现的问题,上架驳回问题处理

This commit is contained in:
liub
2025-09-26 13:50:29 +08:00
parent 21e468c79f
commit 3ac113de3f
6 changed files with 104 additions and 47 deletions

View File

@ -2,7 +2,7 @@
"name" : "星汉物联",
"appid" : "__UNI__A21EF43",
"description" : "设备管控",
"versionName" : "1.0.0",
"versionName" : "1.0.1",
"versionCode" : "100",
"transformPx" : false,
/* 5+App */
@ -60,11 +60,13 @@
"ios" : {
"dSYMs" : false,
"privacyDescription" : {
"NSLocationWhenInUseUsageDescription" : "App需要您的同意,才能在使用期间访问位置",
"NSLocationAlwaysUsageDescription" : "App需要您的同意,才能始终访问位置",
"NSLocationWhenInUseUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
"NSLocationAlwaysUsageDescription" : "App需要您的同意,访问位置,用于判定装备位置是否异常",
"NSLocationAlwaysAndWhenInUseUsageDescription" : "App需要您的同意,才能始终访问位置",
"NSBluetoothPeripheralUsageDescription" : "需要蓝牙访问权限,用于设备通信",
"NSBluetoothAlwaysUsageDescription" : "需要蓝牙访问权限,用于设备通信"
"NSBluetoothPeripheralUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
"NSBluetoothAlwaysUsageDescription" : "App需要您的同意访问蓝牙访问权限,用于设备通信与反向控制",
"NSPhotoLibraryUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面",
"NSPhotoLibraryAddUsageDescription" : "App需要您的同意访问相册,用于上传头像,设备开机画面"
},
"idfa" : false
},

View File

@ -285,6 +285,7 @@
ble.removeReceiveCallback(pagePath);
clearTimeout(this.Statu.timeInteval);
this.device.macAddress=null;
this.Statu.timeInteval=null;
uni.$emit("refreshDeviceList");
setTimeout(() => {

View File

@ -152,11 +152,36 @@
},
onLoad() {
these = this;
this.EquipMents = [];
ble = bleTool.getBleTool();
//已连接过但删除了设备
let delArr = ble.data.deletedEqs.map(v => {
return {
"deviceId": v.deviceId,
"name": v.name,
"RSSI": -99,
"localName": v.name,
}
});
//已连接过但没绑定过的设备
let noDev=ble.data.LinkedList.filter(v=>{
return !(v.device && v.device.id);
}).map(v => {
return {
"deviceId": v.deviceId,
"name": v.name,
"RSSI": -99,
"localName": v.name,
}
});
delArr=delArr.concat(noDev);
console.log("可能搜不到的设备=", delArr);
this.EquipMents = delArr;
ble.addDeviceFound((arr) => {
// console.log("发现新设备,",arr);
arr = arr.devices;
for (var i = 0; i < arr.length; i++) {
@ -164,12 +189,16 @@
if (!arr[i].name) {
continue;
}
let f = these.EquipMents.find(function(v) {
return v.deviceId == arr[i].deviceId;
});
if (!f) {
if (arr[i].deviceId == '35:06:00:EF:46:51') {
console.log("EquipMents=", these.EquipMents);
console.log("arr[i]=", arr[i]);
}
these.EquipMents.push(arr[i]);
} else {
@ -207,6 +236,7 @@
// this.EquipMents = [];
this.PairEquip = [];
ble && ble.StartSearch().then(res => {
console.log("开始搜索成功", res);
@ -216,11 +246,6 @@
these.showOpenSetting();
}
});
},
methods: {
isItemLink: function(item, index) {
@ -260,16 +285,16 @@
}
return false;
});
let removeLink=()=>{
ble.subScribe(deviceId,false);//取消订阅消息
ble.DropDevice(deviceId);//从缓存中删除该设备
ble.disconnectDevice(deviceId);//断开与该设备的连接
let index=this.PairEquip.findIndex(function(v) {
let removeLink = () => {
ble.subScribe(deviceId, false); //取消订阅消息
ble.DropDevice(deviceId); //从缓存中删除该设备
ble.disconnectDevice(deviceId); //断开与该设备的连接
these.device.deviceMac="";
let index = this.PairEquip.findIndex(function(v) {
return v.deviceId == deviceId;
});
if(index>-1){
this.PairEquip.splice(index,1);
if (index > -1) {
this.PairEquip.splice(index, 1);
}
}
@ -302,7 +327,7 @@
this.Status.intval = null;
this.Status.intval = setInterval(() => {
this.Status.time = this.Status.time-1;
this.Status.time = this.Status.time - 1;
if (this.Status.time < 0) {
clearInterval(this.Status.intval)
@ -315,15 +340,15 @@
}
return false;
});
if(!f.macAddress){
if (!f.macAddress) {
removeLink();
updateLoading(these, {
text: "出现错误,未收到设备Mac地址"
});
setTimeout(()=>{
setTimeout(() => {
hideLoading(these)
},1000);
}, 1000);
}
return;
}
@ -387,7 +412,7 @@
}
ble.LinkBlue(item.deviceId).then((res) => {
console.log("连接成功");
ble.StopSearch();
resolve(res);
}).catch((ex) => {
if (index == total) {

View File

@ -467,7 +467,8 @@
if (this.$refs.swipeAction) {
this.$refs.swipeAction.closeAll();
}
console.log("111111",this.deviceId);
console.log("ble==null,",ble)
ble && ble.DropDevice(this.deviceId.id);
} else {
uni.showToast({

View File

@ -72,8 +72,8 @@
data() {
return {
showView: false,
phone: '13800138002', //手机号码
code: "123456", //验证码
phone: '', //手机号码
code: "", //验证码
password: "",
agreed: false,
isCounting: false,

View File

@ -17,6 +17,7 @@ const serviceDic = [ //合作供应商的蓝牙主服务
class BleHelper {
constructor() {
this.StorageKey = "linkedDevices";
this.dropKey = "DeletedDevices";
recei = receivTool.getBleReceive();
this.init();
@ -24,23 +25,26 @@ class BleHelper {
init() {
let key = this.StorageKey;
var store = uni.getStorageInfoSync();
var f = store.keys.find(function(v) {
return v == key;
});
var f = store.keys.includes(key);
var linkedDevices = [];
if (f) {
linkedDevices = uni.getStorageSync(key);
}
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
console.log("111111", linkedDevices);
linkedDevices=linkedDevices.filter((v) => {
linkedDevices = linkedDevices.filter((v) => {
v.Linked = false;
v.notifyState = false;
return v.device && v.device.id;
return true;
});
}
var deletedEqs = [];
f = store.keys.includes(this.dropKey);
if (f) {
deletedEqs = uni.getStorageSync(this.dropKey);
}
setTimeout(() => {
this.OpenBlue().then(() => {
this.linkAllDevices();
@ -54,6 +58,7 @@ class BleHelper {
searchList: [], //已搜索到的设备列表,
isSubscribe: false, //是否开启了订阅
LinkedList: linkedDevices, //已连接的设备列表
deletedEqs: deletedEqs
}
this.cfg = {
onDeviceFound: [], //发现新设备的事件
@ -124,25 +129,47 @@ class BleHelper {
}
//从缓存中删除某个设备bleId蓝牙iddeviceId数据库中的设备id
DropDevice(bleId, deviceId) {
let flag = false;
let delItem=null;
if (!this.data.deletedEqs || !this.data.deletedEqs.length) {
this.data.deletedEqs = [];
}
for (var i = 0; i < this.data.LinkedList.length; i++) {
let item = this.data.LinkedList[i];
if (bleId) {
if (item.deviceId == bleId) {
if (item.device.id == bleId) {
console.log("找到要删除的设备", item);
this.data.LinkedList.splice(i, 1);
this.disconnectDevice(item.deviceId);
flag = true;
delItem=item;
break;
}
} else {
if (item.device && item.device.id) {
if (deviceId && item.deviceId == deviceId) {
console.log("找到要删除的设备1,", item)
this.data.LinkedList.splice(i, 1);
this.disconnectDevice(item.deviceId);
flag = true;
delItem=item;
break;
}
}
}
if (flag) {
this.data.deletedEqs=this.data.deletedEqs.filter(v => {
return v.deviceId != delItem.deviceId;
});
this.data.deletedEqs.push(delItem);
this.updateCache();
}
@ -152,24 +179,25 @@ class BleHelper {
updateCache() {
// console.log("this.StorageKey=", this.StorageKey)
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
uni.setStorageSync(this.dropKey, this.data.deletedEqs);
}
linkAllDevices() {
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
let flag=false;
let flag = false;
for (var i = 0; i < this.data.LinkedList.length; i++) {
let device = this.data.LinkedList[i];
// console.log("自动连接绑定过的设备:" + device.deviceId);
if (device.macAddress && device.device && device.device.id) {
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
.notifyCharactId);
flag=true;
flag = true;
}
}
if(!flag){
if (!flag) {
this.updateCache();
}
} else {
@ -449,7 +477,7 @@ class BleHelper {
this.data.discovering = state.discovering;
if (this.data.available && this.data
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
this.linkAllDevices();
// this.linkAllDevices();
}
}
@ -1346,7 +1374,7 @@ class BleHelper {
uni.closeBLEConnection({
deviceId: id,
success: (res) => {
////console.log("蓝牙连接已断开:" + id);
console.log("蓝牙连接已断开:" + id);
this.subScribe(id, false);
resolve();
},