hbuilder app 热更新 wgt包


const downloadTask = uni.downloadFile({
url: 'http://172.16.20.223:9083/test/download/1.wgt',
complete: (res) => {
console.log(res)
},
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
plus.runtime.install(downloadResult.tempFilePath, {
force: true
}, function() {
console.log('install success...');
plus.runtime.restart();
}, function(e) {
console.error('install fail...');
});
}
}
});

downloadTask.onProgressUpdate((res) => {
console.log('下载进度' + res.progress);
console.log('已经下载的数据长度' + res.totalBytesWritten);
console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
});

 

 

/********************************************************************************/

 

var downLoader = plus.downloader.createDownload('http://172.16.20.223:9083/test/download/1.wgt', {
filename: "_doc/download/"
}, function(downloadObj, status) {
// 下载完成
if (status == 200) {

 

plus.runtime.install(downloadObj.tempFilePath, {
force: true
}, function() {
console.log('install success...');
plus.runtime.restart();
}, function(e) {
console.error('install fail...');
});


} else {
//下载失败
}
});
//downLoader.addEventListener( "statechanged", onStateChanged, false );
downLoader.addEventListener("statechanged", function(download, status) {
if (download.state == 3) {
//download.downloadedSize 已下载长度
//download.totalSize 文件总长度
}
}, false);
downLoader.start();

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM