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