当前位置: 首页 > news >正文

uniapp实现APP版本升级

App.vue 直接上代码

<script>export default {methods: {//APP 版本升级Urlupload() {// #ifdef APP-PLUSplus.runtime.getProperty(plus.runtime.appid, (info) => {// 版本号变量持久化存储getApp().globalData.version = info.version;this.ToLoadUpdate(info.versionCode, );})//#endif},//下载更新ToLoadUpdate(version, ) {uni.showModal({title: `版本更新 ${version}—>${171}`,content: "有更新版本啦!!!",confirmText: '立即更新',cancelText: '稍后更新',showCancel: true,success: (res) => {if (res.confirm) {if (plus.networkinfo.getCurrentType() != 3) { //获取手机设备的相关信息,判断是否在Wifi状态。uni.showToast({title: '检测到您目前非Wifi连接,为节约您的流量,建议您连接WIFI更新!',icon: 'none',duration: 5000});} else {uni.showToast({title: '程序已启动更新,请耐心等待!',icon: 'none',duration: 3000});}//设置 最新版本apk的下载链接const downloadApkUrl ='https://wfgtest-1631.oss.wefanbot.com/DEV/qw/106658768610001/1727229160089/wczd_v1.0.0.apk'console.log("downloadApkUrl===", downloadApkUrl);var dtask = plus.downloader.createDownload(downloadApkUrl, {}, (d, status) => { //新建下载任务if (status == 200) { //当下载完成uni.showModal({title: '下载成功',content: '确定现在安装吗?',confirmText: '立即安装',confirmColor: '#EE8F57',success: (res2) => {if (res2.confirm == true) {plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {},(error) => { //安装应用uni.showToast({title: '安装失败',icon: 'none'});})}}})} else {uni.showToast({title: '更新失败',icon: 'none'});}})dtask.start();var prg = 0;var showLoading = plus.nativeUI.showWaiting("正在下载");dtask.addEventListener('statechanged', (task,status) => { //添加下载任务事件监听器// 给下载任务设置一个监听 并根据状态 做操作switch (task.state) {case 1:showLoading.setTitle("开始下载");break;case 2:showLoading.setTitle("已连接到服务器");break;case 3:prg = parseInt( //下载的进度(parseFloat(task.downloadedSize) /parseFloat(task.totalSize)) *100);showLoading.setTitle("版本更新,正在下载" + prg +"% ");if (prg === 100) {plus.nativeUI.closeWaiting(); //关闭系统提示框}break;case 4:plus.nativeUI.closeWaiting(); //关闭系统提示框//下载完成break;}});} else if (res.cancel) {}}});},},onLaunch() {this.Urlupload()},}
</script>

效果图

http://www.lryc.cn/news/493500.html

相关文章:

  • uniapp强制修改radio-group内单选组件的状态方法
  • 学习python的第十四天之函数——高阶函数和偏函数
  • 数据结构之二叉树详解:从原理到实现
  • iOS 系统中使用 webView 打印 html 的打印边距问题
  • 如何在ubuntu上调试core dump
  • 基于 JNI + Rust 实现一种高性能 Excel 导出方案(上篇)
  • 【Maven】依赖管理
  • springboot/ssm高校超市管理系统Java商品出入库供应商管理系统web源码wms
  • 小程序-基于java+SpringBoot+Vue的微信小程序养老院系统设计与实现
  • 宠物电商对接美团闪购:实现快速配送与用户增值
  • Vue中使用<Transition>与<TransitionGroup>
  • Algorithms and Data Structures in C++ by Mohammed Yasir Eramangadan
  • 2024广东省职业技能大赛云计算——构建CICD 部署2048小游戏
  • React 条件渲染
  • Hadoop生态圈框架部署(九)- Hive部署
  • c语言的qsort函数理解与使用
  • Java 语言的起源发展与基本概念(JDK,JRE,JVM)
  • 03_变量
  • [论文阅读-综述]Supervised Speech Separation Based on Deep Learning: An Overview
  • 群控系统服务端开发模式-应用开发-邮箱配置功能开发
  • 【机器学习】——卷积与循环的交响曲:神经网络模型在现代科技中的协奏
  • android studio引用so库
  • 2024年信号处理与神经网络应用(SPNNA 2024)
  • wxWidgets-ImageView
  • 第1章-JVM和Java体系架构
  • windows 服务器角色
  • [OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
  • C#中判断两个 List<T> 的内容是否相等
  • Linux环境下配置neo4j图数据库
  • Windows 11 搭建 Docker 桌面版详细教程