当前位置:网站首页>Uniapp version update hot update and natural update
Uniapp version update hot update and natural update
2022-06-21 23:09:00 【wh20141212】
Ha ha ha Today to record uniapp How to update the version of
First, it is divided into hot renewal and natural renewal
1. A hot update is a forced update Must be updated When the system appears bug when Or when new functions affect the use Use hot update
2. Natural renewal is Optional updates Click the download button to download Click Cancel to discard the update


All right. Next, code it
- stay App.vue page
Uninstall onLaunch Inside You can also uninstall methods And then in onLaunch call I use the latter method
methods: {
...mapMutations(['login']),// What is not needed here can be commented out
/**
* Detection and update implementation of Android applications
*/
AndroidCheckUpdate: function() {
var _this = this;
var version = 101;
// console.log(version);
uni.request({
// Request address , Set up your own server link
// url: '*************/index.php/System/version', // This is the full domain name
// You can also write the domain name in the warehouse Then it calls In case the domain name is changed back and forth
url: _this.baseUrl +'index.php/System/version',
method: 'POST',
data: {
},
success: resMz => {
console.log(" Version number information ",resMz.data);
// Version number returned
var server_version = resMz.data.data.version;
// Time stamp returned
var currTimeStamp = resMz.data.data.timestamp;
// Status code returned 0 It's natural renewal 1 Is forced update
var status = resMz.data.data.update_status;
console.log(" Local version number version= "+ version + ", Update code ="+status + ", Background version number ="+server_version+ ", Time stamp "+ currTimeStamp);
if (status == 1) {
// Force update Also known as hot update The system appears large bug Must update
_this.MustcheckVersionToLoadUpdate(server_version,version);
} else if (status == 0) {
// Natural renewal
uni.getStorage({
key: 'tip_version_update_time',
success: function(res) {
var lastTimeStamp = res.data;
var tipTimeLength = 0;
console.log( " The time interval ",tipTimeLength);
let cha = lastTimeStamp + tipTimeLength - currTimeStamp;
console.log(" Local time stamp =",lastTimeStamp);
console.log(" Time stamp difference ",cha);
if (lastTimeStamp + tipTimeLength > currTimeStamp) {
// Don't bother here
console.log(' Only when the background timestamp is greater than the local timestamp will it enter ');
} else {
console.log(' Update immediately ');
// Reset timestamp
_this.setStorageForAppVersion(currTimeStamp);
// Compare versions and models And download update requests
console.log(server_version, version);
_this.checkVersionToLoadUpdate(server_version, version);
}
},
fail: function(res) {
_this.setStorageForAppVersion(currTimeStamp);
}
});
}
},
fail: () => {
},
complete: () => {
}
});
},
/**
* // Set the cache information corresponding to the application version number
* @param {
Object} currTimeStamp Currently acquired timestamp
*/
setStorageForAppVersion: function(currTimeStamp) {
uni.setStorage({
key: 'tip_version_update_time',
data: currTimeStamp,
success: function() {
console.log('setStorage-success');
}
});
},
/**
* Compare versions and models And download update requests Natural renewal
* @param {
Object} server_version The server is up to date Application version number
* @param {
Object} curr_version Current application version number
*/
checkVersionToLoadUpdate: function(server_version, curr_version) {
if (server_version > curr_version) {
uni.showModal({
title: ' Version update ',
content: ' There's a new release , Do you want to download the new version now ?',
confirmText: ' Update immediately ',
cancelText: ' Cancel ',
success: function(res) {
if (res.confirm) {
uni.showToast({
icon: 'none',
mask: true,
title: ' There's a new release , The program has started automatic update .',
duration: 5000
});
// Set up The latest version apk Download link for It's fixed Each time you put the package in this link Made by the back end
var downloadApkUrl = 'http://zons.oss-cn-shenzhen.aliyuncs.com/upload/20200616/20200616/159228906014ee22eaba297944c96afdbe5b16c65b.apk';
console.log(downloadApkUrl);
plus.runtime.openURL(downloadApkUrl);
} else if (res.cancel) {
console.log(' Sure next time ');
}
}
});
}
},
/**
* Compare versions and models And download update requests Natural renewal
* @param {
Object} server_version The server is up to date Application version number
* @param {
Object} curr_version Current application version number
*/
MustcheckVersionToLoadUpdate: function(server_version, curr_version) {
if (server_version > curr_version) {
uni.showModal({
title: ' Version update ',
content: ' There's a new release , It is detected that you are currently Wifi Connect , Do you want to download the new version now ?',
confirmText: ' Update immediately ',
showCancel:false,
success: function(res) {
if (res.confirm) {
uni.showToast({
icon: 'none',
mask: true,
title: ' There's a new release , The program has started automatic update .',
duration: 5000
});
// Set up The latest version apk Download link for It's fixed
var downloadApkUrl = 'http://zons.oss-cn-shenzhen.aliyuncs.com/upload/20200616/20200616/159228906014ee22eaba297944c96afdbe5b16c65b.apk';
console.log(downloadApkUrl);
plus.runtime.openURL(downloadApkUrl);
}
}
});
}
},
onLaunch: function() {
this.AndroidCheckUpdate();
}
In addition, I refer to the content of a great God Here is a link
https://www.jianshu.com/p/541c286f69ea
边栏推荐
- [wustctf2020] plain and unpretentious -1
- Software testing Q & A
- WSL 2 的安装过程(以及介绍)
- Niuke month race - insectivores on the ring
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- Guys, some field updates of starrocks PK model in 2.2.1 still do not support SQL, right?
- mvn deploy多个模块的bat文件
- WPF startup with parameters
- WPF x:ArrayExtension
- Common options and commands of Synplify Pro
猜你喜欢

Go service platform project (I) design of database tables and use of gendry Library

Flink实战之实时风控规则引擎

Getting to know Vxe table (I)

uniapp在解决谷歌浏览器跨域问题,在谷歌浏览器运行
Swiftui basic learning journal (XI) SQLite data operation

numpy矩阵初等变换

KVM virtual machine rescue mode modifying root password -- the road to building a dream

Left hand code, right hand open source, part of the open source road

Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading

Professional font design editor glyphs 3
随机推荐
How to adjust the resolution of the computer screen? Computer screen modification resolution switchresx
解决opencv在pycharm中代码提示失效
Text text associated with scroll scroll bar in Tkinter
STM32下载一次程序后就无法再次下载,程序无法运行。
Using JS function in wxml file of applet
《MATLAB 神经网络43个案例分析》:第9章 离散Hopfield神经网络的联想记忆——数字识别
[WUSTCTF2020]朴实无华-1
Precautions for bitmap use
《MATLAB 神经网络43个案例分析》:第19章 基于SVM的手写字体识别
Fedora 36 compiling and installing opencv 4.6.0 -- the road to building a dream
If you spend 200W to buy traffic, it is better to start at 0 cost and make an independent station with high private domain operation income!
MySQL pit records
Required books
Explain JS micro task and macro task in simple terms
Wechat applet obtains network status
C# 删除正在使用的文件
uni-app进阶之样式框架/生产环境【day10】
Set -set
牛客月赛-环上食虫
小程序如何关联微信小程序二维码,并实现二码合一聚合