当前位置:网站首页>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);
}
最后
我相信肯定还有其他比较好的方法,欢迎大家留言,一起相互学习。
边栏推荐
- Linux server development, MySQL transaction principle analysis
- Introduction to basic components of wechat applet
- C language queue
- Pytorch(六) —— 模型调优tricks
- Leetcode 90: subset II
- Ansible
- Explore dry goods! Apifox construction ideas
- pytest+allure+jenkins環境--填坑完畢
- 芯片资料 网站 易特创芯
- Linux server development, MySQL index principle and optimization
猜你喜欢
随机推荐
Why should we understand the trend of spot gold?
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
C language communication travel card background system
王爽 《汇编语言》之寄存器
Introduction to basic components of wechat applet
有 Docker 谁还在自己本地安装 Mysql ?
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
Padavan manually installs PHP
A bit of knowledge - about Apple Certified MFI
Qt学习28 主窗口中的工具栏
Content of string
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Bugku CTF daily one question chessboard with only black chess
Ansible
[mathematical notes] radian
让Livelink初始Pose与动捕演员一致
Thinkcmf6.0 installation tutorial
Common validation comments
![[2022 actf] Web Topic recurrence](/img/e4/ab9a1771489d751ee73a79f151d374.png)







