当前位置:网站首页>uni 热更新
uni 热更新
2022-07-01 07:56:00 【diangedan】
// 检查是否更新版本
updateVersion() {
// 热更新不会更新app的版本号
// 这里用一个常量定义(每次修改版本号将设置里面的版本号手动更新)
let realVersion = '1';
//plus.runtime.getProperty(),获取本机安装的版本,具体使用请参照如下链接
// https: //www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.WidgetInfo
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
let currentVersion = widgetInfo.version.replace(/\./g, ""); //获取当前版本号
sendVersion().then(res => {
const code = res.data.code;
if (code === 100) {
let newVersion = res.data.data.id;
let downloadUrl = res.data.data.downloadUrl;
if (realVersion < newVersion) {
uni.showModal({
title: '已发现新版本',
content: '确认更新?',
success: function(res) {
if (res.confirm) {
uni.downloadFile({
url: downloadUrl,
success: (downloadResult) => {
plus.runtime.install(
downloadResult
.tempFilePath, {
force: true
},
function() {
// 应用热重启,重新启动进入首页。
plus.runtime.restart();
uni.showModal({
title: '安装成功!',
content: '已重新进入应用',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if(res.cancel) {
console.log('用户点击取消');
}
}
});
// uni.hideToast();
},
function(e) {
uni.showToast({
title: '安装失败',
icon: 'none'
})
})
},
fail: (err) => {
console.log(err)
uni.showToast({
title: '下载失败',
icon: 'none'
})
}
})
} else if (res.cancel) {
uni.showToast({
title: '已取消',
icon: 'none'
})
}
}
})
}
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
}
}).catch(err => {
console.log(err)
})
})
},边栏推荐
- 凸印的印刷原理及工艺介绍
- AUTOSAR learning record (1) – ECUM_ Init
- 2022危险化学品经营单位主要负责人试题及模拟考试
- Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
- STM32 uses esp01s to go to the cloud, mqtt FX debugging
- [kv260] generate chip temperature curve with xadc
- [software] phantomjs screenshot
- 浅谈CVPR2022的几个研究热点
- Software testing methods and techniques - overview of basic knowledge
- 论文学习——水文时间序列相似性查询的分析与研究
猜你喜欢

Lm08 mesh series mesh inversion (fine)

Eigen矩阵运算库快速上手

关系数据库如何工作

SQL number injection and character injection

Atguigu---- scaffold --02- use scaffold (2)

组件的自定义事件②

Android screen adaptation (using constraintlayout), kotlin array sorting

2022 operation of refrigeration and air conditioning equipment operation of national question bank simulated examination platform

How to use layui to display the data in the database in the form of tables

Basic knowledge of MATLAB
随机推荐
Scala语言学习-07-构造器
Latex formula code
【网站架构】一招搞定90%的分布式事务,实打实介绍数据库事务、分布式事务的工作原理应用场景
The triode is a great invention
[MySQL learning notes 28] storage function
How to make the two financial transactions faster
She is the "HR of others" | ones character
What information does the supplier need to know about Audi EDI project?
Basic number theory -- combinatorial number
Vhost kick & call principle
The Windows C disk is full
2022茶艺师(初级)操作证考试题库及模拟考试
go通用动态重试机制解决方案的实现与封装
Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years
kubernetes资源对象介绍及常用命令(二)
The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
redisson使用全解——redisson官方文檔+注釋(上篇)
Implementation and encapsulation of go universal dynamic retry mechanism
AUTOSAR learning record (1) – ECUM_ Init
【技能】创建.bat快速打开网页