当前位置:网站首页>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
边栏推荐
猜你喜欢

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!

Analysis of 43 cases of MATLAB neural network: Chapter 9 associative memory of discrete Hopfield Neural Network -- number recognition

WPF thread manipulation UI problem

并查集练习题1:朋友圈

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

Uwp shadow effect

WSL 2 的安装过程(以及介绍)

uniapp封装request函数 实现唯一登录,一个账号同时只能登陆一个设备
uni-app进阶之样式框架/生产环境【day10】

《MATLAB 神经网络43个案例分析》:第19章 基于SVM的手写字体识别
随机推荐
C WindowFromPoint is invalid in 64 bit programs
Functions for automatically calculating bit width during Verilog parameterization
在小程序的 wxml 文件中使用 js 函数
. File header parsing of BMP pictures
WPF startup with parameters
原生小程序 申请小程序 - 发布流程
WPF x:ArrayExtension
Guys, some field updates of starrocks PK model in 2.2.1 still do not support SQL, right?
Wechat applet obtains network status
uni-app进阶之样式框架/生产环境【day10】
1016. 子串能表示从 1 到 N 数字的二进制串
使用云开发实现微信支付的具体方法
《MATLAB 神经网络43个案例分析》:第9章 离散Hopfield神经网络的联想记忆——数字识别
Danfoss inverter maintenance vlt5000/vlt6000/vlt8000
postgis 如何用米制单位 buffer
plt label生效
Better manage all kinds of music, professional DJ music management software pioneer DJ rekordbox
Go service platform project (I) design of database tables and use of gendry Library
C# 删除正在使用的文件
【强烈推荐】Markdown 语法大全