ycm 2 lat temu
rodzic
commit
9880b9f108
1 zmienionych plików z 31 dodań i 1 usunięć
  1. 31 1
      app.js

+ 31 - 1
app.js

@@ -11,7 +11,7 @@ App({
     // wx.cloud.init({
     //   traceUser: true,
     // })
-
+    this.updateApp()
 
     wx.setStorageSync('islocation', false)
     var that = this;
@@ -57,6 +57,36 @@ App({
     })
   },
 
+  updateApp:function(){
+    const updateManager = wx.getUpdateManager()
+    updateManager.onCheckForUpdate(function (res) {
+      // 请求完新版本信息的回调
+      if (res.hasUpdate) {
+        wx.showLoading({
+          title:'更新下载中...',
+        })
+      }
+    })
+    updateManager.onUpdateReady(function () {
+      wx.hideLoading();
+      wx.showModal({
+        title:'更新提示',
+        content:'新版本已经准备好,是否重启应用?',
+        success:function (res) {
+          if (res.confirm) {
+            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+            updateManager.applyUpdate()
+          }
+        }
+      })
+ 
+    })
+    updateManager.onUpdateFailed(function () {
+      // 新的版本下载失败
+      wx.hideLoading();
+      wx.showToast({ title:'下载失败...', icon:"none" });
+    })
+  },
 })