收藏
回答

wx.getUpdateManager怎么在用户使用时可以检测到版本更新以及电脑端使用时如何检测到?

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里面的


回答关注问题邀请回答
收藏

1 个回答

  • 拾忆
    拾忆
    发表于小程序端
    2024-12-21

    官方示例不支持,是在启动时候检测,你可以试试把代码加到其他函数内看看能不能正常检查。

    2024-12-21
    有用
    回复
登录 后发表内容