uniapp 热更新

思路

1、原APP版本号VXXX

2、服务器APP版本号VYYY

3、若 VYYY >  VXXX 则需要升级 

获取原APP版本号VXXX方法

plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{	
				console.log(JSON.stringify(wgtinfo));
				console.log(wgtinfo.versionCode);//应用版本号
})		

wgtinfo

 {"appid":"HBuilder","version":"1.0.3","name":"软件名称","versionCode":"103","description":"软件描述","author":"","email":"","features":["uninview"]}

一般使用 versionCode 来对比,version和versionCode在 manifest.json 中设置

在App.vue的onlunch中写入

plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
					if (res2.data.data.version > wgtinfo.versionCode) {
						uni.showModal({
							title: '新版本更新 ' + res2.data.data.version2,
							content: res2.data.data.intro,
							confirmText: '立即更新',
							cancelText: '取消',
							success: function(res) {
								if (res.confirm) {
									uni.downloadFile({  
										url: res2.data.data.url,  
										success: (downloadResult) => {  
											if (downloadResult.statusCode === 200) {  
												plus.runtime.install(downloadResult.tempFilePath, {  
													force: false  
												}, function() {  
													console.log('install success...');  
													plus.runtime.restart();  
												}, function(e) { 
													console.log(e)
													console.error('install fail...');  
												});  
											}  
										}  
									});  
								} else if (res.cancel) {
									console.log('下次一定');
								}
							}
						}); 
					}
				})

猜你喜欢

转载自blog.csdn.net/sinat_37390744/article/details/108213925