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();