当前位置:网站首页>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
- Linux Installation MySQL 8.0 configuration
- C语言队列
- Linux server development, detailed explanation of redis related commands and their principles
- Codeforce c.strange test and acwing
- 【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
- json 数据展平pd.json_normalize
- Who has docker to install MySQL locally?
- These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
- Content of string
猜你喜欢

Qt学习27 应用程序中的主窗口
![[mathematical notes] radian](/img/43/2af510adb24fe46fc0033d11d60488.jpg)
[mathematical notes] radian

SQL优化的魅力!从 30248s 到 0.001s
![[guess-ctf2019] fake compressed packets](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)
[guess-ctf2019] fake compressed packets

mysql多列索引(组合索引)特点和使用场景

运放电路的反馈电阻上并联一个电容是什么作用

Ansible

Bugku CTF daily one question chessboard with only black chess

Linux server development, redis source code storage principle and data model

LeetCode简单题之判断一个数的数字计数是否等于数位的值
随机推荐
Recursive method to construct binary tree from preorder and inorder traversal sequence
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
You Li takes you to talk about C language 6 (common keywords)
开源生态|打造活力开源社区,共建开源新生态!
Explore Cassandra's decentralized distributed architecture
Rust Versus Go(哪种是我的首选语言?)
【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
Chip information website Yite Chuangxin
Wechat applet data binding multiple data
让Livelink初始Pose与动捕演员一致
PHP exports millions of data
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
Codeforce c.strange test and acwing
2022 welder (elementary) judgment questions and online simulation examination
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
Main window in QT learning 27 application
Zhilian + AV, AITO asked M7 to do more than ideal one
Padavan manually installs PHP
[advanced digital IC Verification] command query method and common command interpretation of VCs tool
SQL优化的魅力!从 30248s 到 0.001s