当前位置:网站首页>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);
}
最后
我相信肯定还有其他比较好的方法,欢迎大家留言,一起相互学习。
边栏推荐
- Value sequence (subsequence contribution problem)
- Most elements
- Why should we understand the trend of spot gold?
- Niu Mei's mathematical problem --- combinatorial number
- 青龙面板-今日头条
- [quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
- Hands on deep learning (IV) -- convolutional neural network CNN
- [mathematical notes] radian
- Linux server development, redis protocol and asynchronous mode
- Explore Cassandra's decentralized distributed architecture
猜你喜欢
随机推荐
[experience sharing] how to expand the cloud service icon for Visio
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
Linux server development, redis source code storage principle and data model
Binary tree and heap building in C language
Custom class loader loads network class
Recursive method constructs binary tree from middle order and post order traversal sequence
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
芯片资料 网站 易特创芯
Chip design data download
Force buckle 145 Binary Tree Postorder Traversal
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
Installing postgresql11 database under centos7
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Pytest+allure+jenkins environment -- completion of pit filling
pytest+allure+jenkins環境--填坑完畢
快速使用 Jacoco 代码覆盖率统计
2022 welder (elementary) judgment questions and online simulation examination



![[guess-ctf2019] fake compressed packets](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)





