监听网络状态和小程序版本更新两个方法写在app.js中的onLaunch中,并同时去调用两个方法。具体如下:
onLaunch: function () {
this.networkManage(); //调用监听网络状态的方法
this.updateManage(); //调用检测小程序版本更新的方法
// ---------------------------------------------网络状态
networkManage: function () {
var that = this;
//监听网络状态
wx.onNetworkStatusChange(function (res) {
if (!res.isConnected) {
that.msg('网络似乎不太顺畅');
}
})
},//--------end
//---------------------------------------------检测小程序版本更新
updateManage: function () {
var that = this;
var updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
if (!res.hasUpdate) {
}
})
// 监听新版本下载成功
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {