版本更新提示

master
lld 2026-01-21 20:08:31 +08:00
parent 77a8a26ca9
commit 7350b39f15
1 changed files with 49 additions and 0 deletions

49
App.vue
View File

@ -23,6 +23,9 @@ export default {
console.log('H5刷新强制断开MQTT连接') console.log('H5刷新强制断开MQTT连接')
}) })
// #endif // #endif
// #ifdef mp-weixin
this.checkMiniProgramUpdate();
// #endif
this.initApp() this.initApp()
mqttUtil.disconnectMqtt() mqttUtil.disconnectMqtt()
@ -184,6 +187,52 @@ export default {
}) })
} }
}) })
},
// +MQTT
checkMiniProgramUpdate() {
// API
if (!uni.canIUse('getUpdateManager')) {
console.log('当前微信版本过低,不支持版本更新检测');
return;
}
if (!uni.canIUse('getUpdateManager')) return;
const updateManager = uni.getUpdateManager();
//
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
console.log('检测到小程序新版本准备清理MQTT');
}
});
// MQTT
updateManager.onUpdateReady(() => {
// MQTT+
mqttUtil.disconnectMqtt()
//
uni.showModal({
title: '版本更新',
content: '新版本已准备好,重启后即可体验',
success: (res) => {
if (res.confirm) {
//
updateManager.applyUpdate();
}
}
});
});
//
updateManager.onUpdateFailed(() => {
mqttUtil.disconnectMqtt()
uni.showToast({
title: '更新失败,已重置连接',
icon: 'none'
});
});
} }
} }
} }