欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > uni-app 版本检测升级

uni-app 版本检测升级

2025/2/5 14:00:11 来源:https://blog.csdn.net/qq_43515724/article/details/145026829  浏览:    关键词:uni-app 版本检测升级

uni-app 版本检测升级 (安卓系统)

  1. pc端管理页面

版本号:必须和app打包 manifest.json 中的版本号一致
在这里插入图片描述

  1. app端

这里直接上代码

// App.vue
<script>export default {data(){return {version:'1.0.0',platform:'ios',}},onLaunch() {console.log('App Launch')// #ifdef APP-PLUSthis.apppanduangengxin()// #endif},methods:{apppanduangengxin(){this.platform = uni.getSystemInfoSync().platform;plus.runtime.getProperty( plus.runtime.appid, ( wgtinfo ) => {this.version = wgtinfo.versionthis.guanyuwomen()});},guanyuwomen(){uni.$u.http.get(`/***`,{}).then(res => {// console.log(this.version,res.data)if(this.version != res.data.version){if (this.platform == 'android') {uni.showModal({title:'版本更新提示',content:res.data.contents,// showCancel:false,success: (res02) => { if (res02.confirm) {console.log("用户点击了确定增量更新");// this.UpdateOfWgt(res)this.UpdateOfApk(res)} else {// uni.$emit("noUpdate", {})console.log("用户点击了取消增量更新");}  }  })}else {// plus.runtime.launchApplication(// 	{// 		action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`// 	},// 	function(e) {// 		console.log(e.message);// 	}// );}}})},UpdateOfApk(result) {let prg = 0;let showLoading = plus.nativeUI.showWaiting("正在下载");  //创建一个showWaiting对象 const downloadTask = uni.downloadFile({url: result.data.downloadLink,  success: (downloadResult) => { plus.nativeUI.closeWaiting();if (downloadResult.statusCode === 200) { console.log('安装包下载成功,即将安装:' + JSON.stringify(downloadResult,null,4));plus.runtime.openFile( downloadResult.tempFilePath )}  }});downloadTask.onProgressUpdate((res) => {// uni.$emit("progress", res)prg = parseInt((parseFloat(res.totalBytesWritten) /parseFloat(res.totalBytesExpectedToWrite)) *100);showLoading.setTitle("  正在下载" + prg + "%  ");// console.log('下载进度' + res);// console.log('已经下载的数据长度' + res.totalBytesWritten);// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);});uni.$on("cancelUpdate", ()=> {console.log("用户点击了取消下载");downloadTask.abort();})},}}
</script>

看懂了吧 为我点点赞

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com