瀏覽代碼

添加自动更新检测

htc 20 小時之前
父節點
當前提交
612f35090a
共有 1 個文件被更改,包括 36 次插入4 次删除
  1. 36 4
      App.vue

+ 36 - 4
App.vue

@@ -4,18 +4,50 @@
 			return {
 				
 			}
-		},
-		methods: {
-			
 		},
 		onLaunch: function() {
 			
 		},
 		onShow: function() {
-			
+			this.autoUpdate();
 		},
 		onHide: function() {
 			
+		},
+		methods: {
+			autoUpdate() {
+				if (wx.canIUse('getUpdateManager')) {
+					const updateManager = wx.getUpdateManager();
+					updateManager.onCheckForUpdate(res => {
+						if (res.hasUpdate) {
+							updateManager.onUpdateReady(() => {
+								wx.showModal({
+									title: '更新提示',
+									content: '发现新版本,是否更新?',
+									success: function(res) {
+										if (res.confirm) {
+											updateManager.applyUpdate();
+										}
+									}
+								})
+							});
+							updateManager.onUpdateFailed(function() {
+								wx.showModal({
+									title: '最新版提示',
+									content: '新版本已上线,请您删除当前小程序,重新搜索打开',
+									showCancel: false
+								})
+							});
+						}
+					})
+				} else {
+					wx.showModal({
+						title: '提示',
+						content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
+						showCancel: false
+					})
+				}
+			}
 		}
 	}
 </script>