蓝牙按工厂要求修改,app隐藏时断开设备蓝牙,已配对设备显示实际连接的设备
# Conflicts: # App.vue
This commit is contained in:
41
App.vue
41
App.vue
@ -1,7 +1,11 @@
|
||||
<script>
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
import upgrade from '@/utils/update.js';
|
||||
|
||||
|
||||
// 延迟断开蓝牙:选择文件/录音等会触发 onHide,8 秒内返回则不断开
|
||||
const BLE_DISCONNECT_DELAY = 8000;
|
||||
let _bleDisconnectTimer = null;
|
||||
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
@ -63,10 +67,10 @@
|
||||
});
|
||||
}
|
||||
if (plus.os.name == 'Android') {
|
||||
if(plus.runtime.isAgreePrivacy()){
|
||||
initOS();
|
||||
if (plus.runtime.isAgreePrivacy()) {
|
||||
initOS();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
initOS();
|
||||
}
|
||||
|
||||
@ -74,7 +78,11 @@
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show');
|
||||
|
||||
// 取消延迟断开:用户可能只是选文件/录音后返回,不断开蓝牙
|
||||
if (_bleDisconnectTimer) {
|
||||
clearTimeout(_bleDisconnectTimer);
|
||||
_bleDisconnectTimer = null;
|
||||
}
|
||||
//将检查更新换到onshow,因为苹果用户喜欢一直挂着
|
||||
// #ifdef APP|APP-PLUS
|
||||
|
||||
@ -91,13 +99,26 @@
|
||||
onHide: function() {
|
||||
console.log('App Hide');
|
||||
// #ifdef APP|APP-PLUS
|
||||
// 上传中不主动断开:语音上传进行中则不断开蓝牙
|
||||
let ble = bleTool.getBleTool();
|
||||
if (ble) {
|
||||
console.log("App隐藏了,断开所有蓝牙设备,停止搜索");
|
||||
ble.StopSearch().catch(ex=>{});
|
||||
ble.disconnectDevice().catch(ex=>{});
|
||||
|
||||
if (ble && ble.isVoiceUploading && ble.isVoiceUploading()) {
|
||||
console.log('App Hide: 语音上传中,不启动断开定时器');
|
||||
return;
|
||||
}
|
||||
// 延迟断开:选文件/录音会短暂 onHide,8 秒内返回则不断开
|
||||
if (_bleDisconnectTimer) clearTimeout(_bleDisconnectTimer);
|
||||
_bleDisconnectTimer = setTimeout(() => {
|
||||
_bleDisconnectTimer = null;
|
||||
let ble2 = bleTool.getBleTool();
|
||||
if (ble2) {
|
||||
console.log("App隐藏了,断开所有蓝牙设备,停止搜索");
|
||||
ble2.StopSearch().catch(ex => {});
|
||||
ble2.disconnectDevice().catch(ex => {});
|
||||
console.log("断开所有蓝牙设备");
|
||||
|
||||
|
||||
}
|
||||
}, BLE_DISCONNECT_DELAY);
|
||||
// #endif
|
||||
},
|
||||
onError(ex) {
|
||||
|
||||
Reference in New Issue
Block a user