+-
首页 专栏 小程序 文章详情
闫雪 发布于 2 月 1 日
关注作者
关注作者
0
微信小程序 版本强制更新,检测到新版本重启小程序
实现 小程序版本强制更新,用户即可完成更新最新版本,检测到新版本重启小程序。
修改app.js 的 onLaunch
方法
//app.js
App({
onLaunch: function () {
// 版本自动更新代码
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新检测',
content: '检测到新版本,是否重启小程序?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已有新版本咯',
content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索“天助定餐饮”打开呦~',
showCancel: false
})
})
}
})
本地测试,新建编译条件,关键是测试版本更新的时候每次都要勾选“下次编译时模拟更新”
即可。
版本更新 小程序
阅读 49 发布于 2 月 1 日
赞
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
闫雪
专栏
关注专栏
闫雪
9 声望
5 粉丝
0 条评论
得票 时间
提交评论
闫雪
9 声望
5 粉丝
宣传栏
目录
▲
实现 小程序版本强制更新,用户即可完成更新最新版本,检测到新版本重启小程序。
修改app.js 的 onLaunch
方法
//app.js
App({
onLaunch: function () {
// 版本自动更新代码
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新检测',
content: '检测到新版本,是否重启小程序?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已有新版本咯',
content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索“天助定餐饮”打开呦~',
showCancel: false
})
})
}
})
本地测试,新建编译条件,关键是测试版本更新的时候每次都要勾选“下次编译时模拟更新”
即可。