
uniapp开发app的webview页面app内下载其他app需要给一个apk的下载地址export default { update(fileName) { let downURL fileName; //后台显示进度条 let isapkuni.getStorageSync(apk) console.log(下载地址, isapk); if(isapk){ uni.showModal({ title: 下载完成, content: 请点击允许安装应用, success: (res) { if (res.confirm) { install(isapk, 200); }else{ signOut() } }, }); }else{ let dtask plus.downloader.createDownload( downURL, {}, function(d, status) { //下载完成 uni.setStorageSync(apk,d) uni.showModal({ title: 下载完成, content: 请点击允许安装应用, success: (res) { if (res.confirm) { install(d, status); }else{ signOut() } }, }); } ); start(dtask); } } } function start(dtask) { try { dtask.start(); //开启下载项目 let prg 0; let showLoading plus.nativeUI.showWaiting(正在下载); dtask.addEventListener(statechanged, function(task, status) { switch (task.state) { case 1: showLoading.setTitle(正在下载); break; case 2: showLoading.setTitle(已连接到服务器); break; case 3: prg parseInt( (parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100 ); showLoading.setTitle( 正在下载 prg % ); break; case 4: plus.nativeUI.closeWaiting(); break; } }); } catch (err) { plus.nativeUI.closeWaiting(); uni.showToast({ title: 更新失败-03, mask: false, duration: 1500, }); } }; function install(d, status) { //下载完成 if (status 200) { plus.runtime.install(d.filename, { force: false }, function() { plus.nativeUI.closeWaiting(); uni.removeStorageSync(apk) }, function(e) { plus.nativeUI.closeWaiting(); uni.removeStorageSync(apk) console.log(安装wgt文件失败[ e.code ] e.message); plus.nativeUI.alert(安装wgt文件失败[ e.code ] e.message); }); } else { uni.showToast({ title: 下载失败, mask: false, duration: 1500, }); } };