当前位置:网站首页>Uni hot update

Uni hot update

2022-07-01 07:59:00 diangedan

//  Check whether the version is updated 
updateVersion() {
    //  Hot update will not update app Version number of 
	//  Here we use a constant to define ( Each time you modify the version number, you will manually update the version number in the settings )
	let realVersion = '1';
	//plus.runtime.getProperty(), Get the locally installed version , Please refer to the following links for specific use     
	// https: //www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.WidgetInfo
	plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
		let currentVersion = widgetInfo.version.replace(/\./g, ""); // Get the current version number 
		sendVersion().then(res => {
			const code = res.data.code;
			if (code === 100) {
				let newVersion = res.data.data.id;
				let downloadUrl = res.data.data.downloadUrl;
				if (realVersion < newVersion) {
					uni.showModal({
						title: ' A new version has been found ',
						content: ' Confirm update ?',
						success: function(res) {
							if (res.confirm) {
								uni.downloadFile({
									url: downloadUrl,
									success: (downloadResult) => {
										plus.runtime.install(
											downloadResult
											.tempFilePath, {
													force: true
											},
											function() {
											//  Application hot restart , Restart to enter the home page .
												plus.runtime.restart();
													uni.showModal({
													    title: ' Installation successful !',
														content: ' Re entered the app ',
														success: function(res) {
																	if (res.confirm) {
																		console.log(' The user clicks ok ');
																	} else if(res.cancel)                 {
                                                                        console.log(' The user clicks cancel ');
																	}
																}
															});
															// uni.hideToast();
														},
														function(e) {
															uni.showToast({
																title: ' Installation failed ',
																icon: 'none'
															})
														})
												},
												fail: (err) => {
													console.log(err)
													uni.showToast({
														title: ' Download failed ',
														icon: 'none'
													})
												}
											})
										} else if (res.cancel) {
											uni.showToast({
												title: ' Cancelled ',
												icon: 'none'
											})
										}
									}
								})
							}
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
 
					}).catch(err => {
						console.log(err)
					})
 
				})
			},

原网站

版权声明
本文为[diangedan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010755431506.html