function checkUpdateVersion() {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '温馨提示',
content: '检测到新版本,是否重启小程序?',
showCancel: false,
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate();
}
},
});
});
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已有新版本',
content: '请您卸载小程序,重新搜索进入',
showCancel: false,
confirmText: '知道了',
});
});
}
});
} else {
wx.showModal({
title: '温馨提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
});
}
}
module.exports = {
checkUpdateVersion,
};
现在是放在onLaunch里面的
官方示例不支持,是在启动时候检测,你可以试试把代码加到其他函数内看看能不能正常检查。