uniapp安卓在线更新版本
实现逻辑
通过获取线上的版本号和app的版本号进行对比 查看是不是最新版 — app版本号小于线上版本号则不是最新版 提示更新
模拟检测更新请求
起一个服务,也就是检测更新的接口
返回值为最新版本号和最新版wgt文件下载地址,例:
{
"code": 0,
"msg": "success",
"version": "101",
"url": "http://192.168.1.160:5501/download/trq101.wgt"
}
应用使用
应用内检测更新方法
//检测版本更新 const version = ref() const innerVer = ref() const checkVersion = () => { plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => { innerVer.value = widgetInfo.version; version.value = widgetInfo.versionCode; uni.request({ url: 'http://192.168.1.160:5501/download/smartAppversion.json?_t=' + new Date().getTime(), //版本检测 data: {}, header: {}, success: (result) => { console.log(result.data,version.value) if (result.data.code === 0) { if (result.data.version - version.value > 0) { // 如果最新版本大于现在已经安装的App的版本 uni.showModal({ title: "更新提示", content: "发现新版本,请确认下载更新?", success: (res) => { if (res.confirm) { uni.showLoading({ title: '下载更新包中...' }); uni.downloadFile({ url: result.data.url, success: (downloadResult) => { uni.hideLoading(); if (downloadResult.statusCode === 200) { plus.runtime.install(downloadResult.tempFilePath, { force: true }, function () { console.log('App更新成功!'); uni.showModal({ title: 'App更新成功!', showCancel: false }) plus.runtime.restart(); }, function (e) { console.log('App更新失败!'); }) } } }); } } }) } else { uni.showModal({ title: '当前已是最新版本', showCancel: false }) } } } }) }) }
在想使用的时候调用即可
本文来自博客园,作者:脆,转载请注明原文链接:https://www.cnblogs.com/Wei-notes/p/18146467
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2023-04-19 记录常用的爬虫代码段(长期更新)