UNI-APP APP升级(整包升级与热升级)
来源:     阅读:1683
云上智慧
发布于 2020-04-24 15:07
查看主页

1.服务端数据格式

{

"android":{

"updateType":0, ??

????"appVersion":"1.0.0",

????"wgtUdateUrl":"http://10.168.10.1/app.wgt",

"downloadUrl":"https://www.lanzous.com/game"

},

"ios":{

"updateType":0, ??

????"appVersion":"1.3.0", ?

????"wgtUdateUrl":"http://106.13.40.12/__UNI__1EA9FB7.wgt",

"downloadUrl":"https://www.lanzous.com/game-ios"

}

}



参数名称:

1.updateType升级类型(0热升级,1整包升级)

2.appVersion ???APP版本

3.wgtUdateUrl ?wgt(热升级资源包)下载地址

4.downloadUrl整包升级下载地址

注意:

APP版本号均要大于前一个版本号

肯定大于上一个版本(部分手机无法降级安装安装包)


wgt资源包生成: ???




2.用户端(APP端)


//APP升级

export function appUdate(appInfo) {

let appVersion = appInfo.version.replace(/[.]/g, "") //当前版本号

let appName = appInfo.name //app名字

let phoneOS = uni.getSystemInfoSync().platform

uni.request({

url: 'http://***********',

//url: '',

method: 'GET',

success: res => {

let androidUdateFile = res.data.android //安卓升级文件

let iosUdateFile = res.data.ios //ios升级文件

// let updateFile = {}

let updateFile = phoneOS == "android" ? androidUdateFile : iosUdateFile

console.log(updateFile)

// if (phoneOS === "android") {

// updateFile = androidUdateFile

// } else {

// updateFile = iosUdateFile

// }

if (updateFile.appVersion.replace(/[.]/g, "") > appVersion) {

if (updateFile.updateType) {

packageDownload(updateFile) //整包升级

} else {

wgtDownload(updateFile) //wgt升级

}

}

},

fail: () => {


},

});

}


//热升级

function wgtDownload(fileInfo) {

const downloadTask = uni.downloadFile({

url: fileInfo.wgtUdateUrl,

success: (downloadResult) => {

if (downloadResult.statusCode === 200) {

uni.showModal({

title: "提醒",

content: '软件升级完成,能否重启应用?',

success: res => {

if (res.confirm) {

(downloadResult.tempFilePath, {

force: false

}, function() {

console.log('install success...');

plus.runtime.restart();

}, function(e) {

console.error('install fail...');

});

}

}

});

}

}

});


downloadTask.onProgressUpdate((res) => {

console.log('下载进度' + res.progress);

})

}


//整包升级

function packageDownload(fileInfo) {

uni.showModal({

title: "提醒",

content: `测到有最新版本${fileInfo.appVersion},能否确认升级?`,

success: function(res) {

if (res.confirm) {

plus.runtime.openURL(fileInfo.downloadUrl) //整包下载

}

}

});

}



一般封装成一个js import引入就行



本人在App.vue文件

onLaunch里面执行以下代码

plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {

appUdate(wgtinfo)

})

需要在哪升级就放在哪里

免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 系统环境 服务器应用
相关推荐
首页
搜索
订单
购物车
我的