在App.js中添加
onLaunch: function() {
// 获取小程序更新机制兼容
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function(res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
wx.showModal({
title: '更新提示',
content: '新版本已经上线啦~,为了获得更好的体验,建议立即更新',
showCancel: false,
confirmColor: "#5677FC",
success: function(res) {
var self=this
wx.showLoading();
//静默下载更新小程序新版本
updateManager.onUpdateReady(function () {
wx.hideLoading()
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
})
updateManager.onUpdateFailed(function () {
wx.hideLoading()
// 新的版本下载失败
// 新的版本下载失败
wx.showModal({
title: '更新失败',
content: '新版本更新失败,为了获得更好的体验,请您删除当前小程序,重新搜索打开',
confirmColor: "#5677FC",
showCancel: false
})
})
}
})
}
})
} else {
// 当前微信版本过低,无法使用该功能
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
confirmColor: "#5677FC",
showCancel: false
})
}
},