CheckUpdateVersion.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. // utils/index.js
  2. export function checkUpdateVersion() {
  3. //创建 UpdateManager 实例
  4. const updateManager = uni.getUpdateManager();
  5. //检测版本更新
  6. updateManager.onCheckForUpdate(function(res) {
  7. // 请求完新版本信息的回调
  8. if (res.hasUpdate) {
  9. //监听小程序有版本更新事件
  10. updateManager.onUpdateReady(function() {
  11. uni.showModal({
  12. title: '更新提示',
  13. content: '新版本已经准备好,是否重启应用?',
  14. success(res) {
  15. if (res.confirm) {
  16. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  17. updateManager.applyUpdate();
  18. }
  19. }
  20. })
  21. })
  22. updateManager.onUpdateFailed(function() {
  23. // 新版本下载失败
  24. uni.showModal({
  25. title: '已经有新版本咯~',
  26. content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开呦~',
  27. })
  28. })
  29. }
  30. })
  31. }