当前位置:网站首页>uniapp 移动端强制更新功能
uniapp 移动端强制更新功能
2022-07-07 04:56:00 【涛涛之海】
uniapp 移动端强制更新功能
背景
最近,考虑到移动端版本的迭代升级,需要有强制更新的功能,整体逻辑比较简单,我之前没有做过,于是简单记录一下。
前端
需要一打开移动端的app,就要进行版本号的判断,所以需要在app.vue 文件中的 onLaunch()方法中写代码逻辑。

// 强制更新
//#ifdef APP-PLUS
this.$u.api.update({
appid: plus.runtime.appid,
version: plus.runtime.versionCode
})
.then(res => {
console.log(res);
console.log(plus.runtime.appid);
console.log(plus.runtime.versionCode);
console.log(res.status);
if (res.status == 1) {
uni.showModal({ //提醒用户更新
title: "更新提示",
showCancel: false, // 将取消按钮隐藏
content: res.note,
buttonText: '确定',
success: (rese) => {
if (rese.confirm) {
plus.runtime.openURL(res.url); // 调用手机端的浏览器 进行下载
}
}
})
}
});
//#endif
后端
/**
* 强制 更新校验
* @param appid
* @param version
* @return
*/
@RequestMapping("/update")
public ResponseEntity<Map<String, String>> update(String appid, String version) {
Map<String, String> map = new HashMap<>();
// 获取数据库中存放的升级版本,升级内容以及下载链接
AppUpdateApk appUpdateApk = appUpdateApkService.findNew();
String mVersion = appUpdateApk.getVersionNumber();
// 移动端的版本号 与数据库最新的版本号进行比对
if(mVersion.equals(version)){
map.put("status","0");
}else{
// 不同的进行提醒
map.put("status","1");
map.put("note",appUpdateApk.getUpdateContent());
map.put("url",appUpdateApk.getUrl());
}
return ResponseEntity.ok(map);
}
最后
我相信肯定还有其他比较好的方法,欢迎大家留言,一起相互学习。
边栏推荐
- Redis technology leak detection and filling (II) - expired deletion strategy
- Linux server development, MySQL transaction principle analysis
- dash plotly
- 芯片 設計資料下載
- 2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
- C language queue
- C语言二叉树与建堆
- [UVM foundation] what is transaction
- 2022 welder (elementary) judgment questions and online simulation examination
- 微信小程序基本组件使用介绍
猜你喜欢
![[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替](/img/e3/cceede6babae3c8a24336c81d98aa7.jpg)
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替

【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO

Why should we understand the trend of spot gold?

You Li takes you to talk about C language 6 (common keywords)

LeetCode 40:组合总和 II
![[mathematical notes] radian](/img/43/2af510adb24fe46fc0033d11d60488.jpg)
[mathematical notes] radian

2022制冷与空调设备运行操作复训题库及答案

Li Kou interview question 04.01 Path between nodes

Main window in QT learning 27 application

Linux server development, redis source code storage principle and data model
随机推荐
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
Bugku CTF daily one question chessboard with only black chess
The charm of SQL optimization! From 30248s to 0.001s
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
JS quick start (I)
B. Value sequence thinking
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
QT learning 28 toolbar in the main window
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Rust versus go (which is my preferred language?)
让Livelink初始Pose与动捕演员一致
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
CTF daily question day43 rsa5
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
有 Docker 谁还在自己本地安装 Mysql ?
芯片 設計資料下載
You Li takes you to talk about C language 6 (common keywords)
Visualization Document Feb 12 16:42
[unity] several ideas about circular motion of objects
Most elements