Browse Source

添加强制更新

puyao 9 hours ago
parent
commit
257c225ced
2 changed files with 35 additions and 2 deletions
  1. 33 0
      App.vue
  2. 2 2
      manifest.json

+ 33 - 0
App.vue

@@ -8,6 +8,7 @@
 			wsUrl: 'wss://websocket.cdwjyyh.com',
 		},
 		onLaunch: function() {
+			this.checkUpdate()
 			// uni.$TUIKit = TIM.create({
 			// 	SDKAppID: 1400693126
 			// });
@@ -77,6 +78,38 @@
 		},
 		 
 		methods: {
+			checkUpdate() {
+				const updateManager = uni.getUpdateManager();
+				updateManager.onCheckForUpdate(function(res) {
+					// 请求完新版本信息的回调
+					console.log('是否有新版本:', res.hasUpdate);
+				});
+			
+				updateManager.onUpdateReady(function() {
+					uni.showModal({
+						title: '更新提示',
+						content: '新版本已经准备好,是否重启小程序?',
+						confirmText: '立即重启',
+						confirmColor: '#2179f5',
+						showCancel: false,
+						success(res) {
+							if (res.confirm) {
+								// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+								updateManager.applyUpdate();
+							}
+						}
+					});
+				});
+			
+				updateManager.onUpdateFailed(function() {
+					// 新的版本下载失败
+					uni.showModal({
+						title: '更新提示',
+						content: '新版本下载失败,请检查网络后重试。',
+						showCancel: false
+					});
+				});
+			},
 			// TODO:
 			resetLoginData() {
 				// this.globalData.expiresIn = '';

+ 2 - 2
manifest.json

@@ -1,7 +1,7 @@
 {
-    "name" : "芳华佳",
+    "name" : "芳华佳",
     "appid" : "__UNI__7931688",
-    "description" : "",
+    "description" : "芳华佳选",
     "versionName" : "1.0.0",
     "versionCode" : "100",
     "transformPx" : false,