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

组件的自定义事件①

Introduction to kubernetes resource objects and common commands (II)

web254

2022电工(中级)复训题库及答案

H5 页面设置了字体的粗细样式,但是在华为手机里微信打开访问样式不生效?

图扑软件通过 CMMI5 级认证!| 国际软件领域高权威高等级认证

2022 mobile crane driver test exercises and online simulation test

What information does the supplier need to know about Audi EDI project?

源代码加密的意义和措施

Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years
随机推荐
【网站架构】一招搞定90%的分布式事务,实打实介绍数据库事务、分布式事务的工作原理应用场景
How to get a SharePoint online site created using the office365 group template
Redisson uses the full solution - redisson official documents + comments (Part 2)
2022 electrician (intermediate) recurrent training question bank and answers
Caesar
【mysql学习笔记28】存储函数
AArdio - 【问题】bass库回调时内存增长的问题
[MySQL learning notes 25] SQL statement optimization
Source code analysis of open source API gateway APIs IX
038 network security JS
I bet on performance and won the CTO of the company. I want to build Devops platform!
十大劵商如何开户?另外,手机开户安全么?
Rk3399 platform development series explanation (network debugging) 7.30. What will affect the sending process of TCP packets?
Saving db4i depth camera pictures with MATLAB
Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years
Software testing methods and techniques - overview of basic knowledge
她就是那个「别人家的HR」|ONES 人物
【技能】创建.bat快速打开网页
The database is locked. Is there a solution
matlab保存DB4i深度相机图片