/* 开始自动下载 */
export function startUpdate() {
const url = "" //文件下载地址
const downTask = plus.downloader.createDownload(url, {}, downloadCallback)
downTask.addEventListener("statechanged", listenStatechanged)
downTask.start()
}
/* 下载成功或失败回调 */
function downloadCallback(file, status) {
if(status != 200) return console.log("下载失败")
plus.runtime.openFile(file.filename) //运行apk
}
/* 监听下载进度 */
function listenStatechanged(task) {
console.log((parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100)
}
Uniapp——实现下载并自动更新app
于 2022-08-29 17:53:29 首次发布