uniapp 热更新和整包更新

首先获本地版本号

			// #ifdef APP-PLUS 
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
    
    
				console.log(widgetInfo.version);
			});
			// #endif

每次上传后台的热包版本要比之前的大

在这里插入图片描述

下载文件资源到本地

再请求接口本地版本要是比上传版本高就下载上传版本

下载高版本

					uni.downloadFile({
    
    
					url: ,//地址
					success: res => {
    
    
						console.log('下载地址', res)
						if (res.statusCode === 200) {
    
    
							//返回一个高版本的包
							_this.installWgt(res.tempFilePath);
						}
					},
				});

这里整包更新是直接安装,热更新要重新启动

plus.runtime.restart(); // 重新启动
		installWgt(path,val) {
				// #ifdef APP-PLUS
				let _this = this;
				plus.runtime.install(
					path, {
						force: true
					},
					function() {
						//成功的操作
					},
					function(e) {
						plus.nativeUI.closeWaiting();
						plus.nativeUI.alert('更新失败' + '[' + e.code + ']:' + e.message); //更新失败
					}
				);
				// #endif
			},

最后,给整包更新弄个提示,提醒用户要更新,不更新直接退出

// #ifdef APP-PLUS
plus.runtime.quit();
// #endif

猜你喜欢

转载自blog.csdn.net/weixin_55552785/article/details/119347329
今日推荐