/**
* 检测当前的小程序
* 是否是最新版本,是否需要下载、更新
*/
checkUpdateVersion: function () {
//判断微信版本是否 兼容小程序更新机制API的使用
if (wx.canIUse('getUpdateManager')) {
//创建 UpdateManager 实例
const updateManager = wx.getUpdateManager(); // 获取更新管理器对象
updateManager.onCheckForUpdate(function (res) {
// console.log(res) 检测更新结果
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,点击确定重新启动',
showCancel: false,
success: res => {
if (res.confirm) {
updateManager.applyUpdate();
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '提示',
content: '检查到有新版本,但是下载失败,请检查网络设置',
showCancel: false
})
})
}
})
} else {
//TODO 此时微信版本太低(一般而言版本都是支持的)
wx.showModal({
title: '溫馨提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
},