这里只说安卓的应用,软件包放在自己的服务器中。
三种方式
- apk包整包更新,要下载所有的文件包含权限模块依赖等,大小在20M+
- wgt包应用资源更新,只更新自己写的代码,根据你代码的多少大小在600k左右
- wgtu应用资源差量升级,只更新自己写的代码改变的那一小部分100k左右(实现起来有点复杂这里不讨论)
场景说明
如果你改了App模块配置,权限配置等这些mainifest.json里面的东西,那么就需要apk包整包升级,如果你只是改了代码里的某个地方的bug,或者增减模块这些,那么只需要更新应用资源包就可以了。
apk打包
- 1、代码修改完
- 2、修改manifest.json中的应用版本名称和应用版本号
- 3、发行
- 4、云打包
wgt打包
- 1、代码修改完
- 2、修改manifest.json中的应用版本名称和应用版本号
- 3、发行
- 4、制作应用wgt包
代码
mdLoading是自己写的一个提示
// 获取最新版本信息
getVersion() {
let that = this;
// #ifdef APP-PLUS
uni.showLoading({
title: '正在获取最新版本信息...'
});
//这里用setTimeout模拟请求
setTimeout(() => {
uni.hideLoading();
let onLineVersion = 105;
//这里通过请求接口判断版本
// onLineVersion > plus.runtime.versionCode
if (true) {
uni.showModal({
title: '发现新版本是否升级?',
content: `
1、新增个人信息模块
2、新增版本信息模块
`,
success(res) {
if (res.confirm) {
that.content = '下载中...'
that.$refs.mdLoading.show()
let downloadTask = uni.downloadFile({
// url: 'http://xxxxxx:8081/xxxxxx.wgt',
//这个地址是请求后台接口返回的
url:'http://xxxxxxxx:8081/xxxxxx.apk',
success(downloadResult) {
if (downloadResult.statusCode === 200) {
that.content = '下载完成,安装中...'
plus.runtime.install(
downloadResult.tempFilePath,
{
force: true
},
function() {
that.content = '应用更新完成稍后将重启应用'
setTimeout(() => {
that.$refs.mdLoading.hide()
plus.runtime.restart();
}, 1000);
},
function(e) {
uni.showToast({
icon: 'none',
title: e
});
}
);
}else{
that.content = '应用下载失败'
that.$refs.mdLoading.hide()
}
},
fail(e){
that.content = e
setTimeout(()=>{
that.$refs.mdLoading.hide()
},1000)
}
});
// 监听下载进度
downloadTask.onProgressUpdate((e)=>{
that.content = '下载中...'+ e.progress + ' %';
})
}
}
});
} else {
uni.showToast({
icon: 'none',
title: '当前已经是最新版本'
});
}
}, 1000);
// #endif
}
mdLoading文件
<template>
<view>
<view v-show="visible" class="fy-loading flex justify-center">
<view class="box flex flex-column align-center">
<view class="loading">
<image src="/static/loading.gif"></image>
</view>
<view class="content">{
{content}}</view>
</view>
</view>
</view>
</template>
<script>
export default{
name:'fy-loading',
props:{
content:{
type:String,
default:''
}
},
data() {
return {
visible: false
}
},
methods:{
show(){
this.visible = true;
},
hide(){
this.visible = false;
}
}
}
</script>
<style scoped lang="scss">
.fy-loading{
position: fixed;
left:0;
top:0;
right:0;
bottom:0;
width:100vw;
height: 100vh;
z-index:100;
background: rgba(0,0,0,0.6);
overflow: hidden;
}
.box{
width:100px;
height: 70px;
margin-top:30vh;
}
.content{
color:#fff;
font-size:14px;
text-align:center;
margin-top:10px;
}
.loading{
width:40px;
height: 40px;
}
.loading image{
width:100%;
height: 100%;
}
</style>