uniapp 使用wgt包 您所在的位置:网站首页 uniapp运行到浏览器页面怎么那么大 uniapp 使用wgt包

uniapp 使用wgt包

2023-06-04 18:15| 来源: 网络整理| 查看: 265

我们在打包App 以后 每次更新 都得去打包一次Apk 而每次上传,别人都得重新下载一次Apk 这样会很麻烦, 每次用户更新都得去再次下载App 我们如果只更改了一点点东西,用户如何不需要再次下载App 如果是没有太大的修改,只修改bug和部分功能 我们就可以利用 wgt包进行替换

首先我们需要去做 uniapp App更新 先选择完更新版本

在这里插入图片描述 1、客户端检查手机型号

let that = this; uni.getSystemInfo({ success:(res) => { console.log(res.platform); //检测当前平台,如果是安卓则启动安卓更新 if(res.platform=="android"){ that.AndroidCheckUpdate(); } } })

2、、检查版本更新差异

AndroidCheckUpdate() { let that = this; plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { that.version = wgtinfo.version //客户端版本号 console.log('当前app版本信息:' + that.version); }) that.getUpdateVersion() }, getUpdateVersion() { let that = this; // 获取当前app版本信息 that.$req.get("/appUpdate/queryUpdate", { }, {}).then(function (res) { console.log('res.data:' + JSON.stringify(res.data)) console.log("现在的版本"+ that.version +"数据库版本"+ res.data.data.version +"进入查找app版本"); if(res.data.data.version>that.version){ // 这里下载apkurl从/appUpdate/queryUpdate接口请求返回数据中获取 that.downloadUrl = BaseUrl + '/' + res.data.data.androidUrl // 是否强制更新(0 否;1 是) that.isForceUpdate = res.data.data.isForceUpdate uni.showModal({ // 更新提醒 title: '发现新版本,是否更新', content: '此版本号:'+ that.version + '\xa0\xa0\xa0' + '待更新版本号:' + res.data.data.version, success: res => { if (res.confirm) { that.downWgt();//下载文件 // that.showdownLine = true; // plus.runtime.openURL(androidUrl) } else if (res.cancel) { console.log('that.isForceUpdate:' + that.isForceUpdate); // 不更新强制退出app if (that.isForceUpdate == 1) { console.log('that.isForceUpdate1:' + that.isForceUpdate); uni.showModal({ // 更新提醒 title: '发现新版本,是否更新', content: '此版本为强制更新版本如不升级将退出APP', success: res => { if (res.confirm) { console.log('不更新强制退出app'); plus.runtime.quit(); } else if (res.cancel) { that.AndroidCheckUpdate(); } } }); } } } }); //dtask.start(); } }).catch(error => { uni.showToast({ title: '调用请求失败', mask: false, duration: 5000, icon:"none" }); }); complete: () => {} },

3找到你更新的地址 把包刚打包的文件进行上传到下载的地址链接加粗样式** 在这里插入图片描述

选择完你更新的地址以后

4、确认更新后下载APK包安装包

downWgt() { let that=this; console.log('url:' + that.downloadUrl) uni.showLoading({ title: '更新中……' }) const downloadTask = uni.downloadFile({//执行下载 url: that.downloadUrl, //下载地址 timeout: 1000 * 30, //30秒超时时间 success: downloadResult => {//下载成功 that.showdownLine = false uni.hideLoading(); console.log('downloadResult.statusCode' + downloadResult.statusCode) if (downloadResult.statusCode == 200) { console.log('更新中') uni.showModal({ title: '', content: '更新成功,确定现在重启吗?', confirmText: '重启', confirmColor: '#EE8F57', success: function(res) { if (res.confirm == true) { plus.runtime.install(//安装 downloadResult.tempFilePath, { force: true }, function(res) { utils.showToast('更新成功,重启中'); plus.runtime.restart(); } ); } } }); } }, fail: err => { uni.hideLoading(); that.showdownLine = false that.$u.toast(err.errMsg) console.log(err) }, complete: com => { console.log(com) } }); // 下载进度 downloadTask.onProgressUpdate(res => { // that.$u.toast(res.progress) that.downloadNum = res.progress console.log('下载进度' + that.downloadNum); // console.log('已经下载的数据长度' + res.totalBytesWritten); // console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite); // 满足测试条件,取消下载任务。 // if (res.progress > 50) { // downloadTask.abort(); // } }); },


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有