uniapp 使用wgt包

文章介绍了使用uniapp开发的App如何实现更新,通过检查手机型号和版本信息,对比服务器上的版本,仅在必要时下载wgt包或Apk进行更新。在安卓平台上,当有更新可用时,用户可以选择下载并安装,如果是强制更新,则会提示用户必须更新才能继续使用。
摘要由CSDN通过智能技术生成

我们在打包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();
    // }
  });
},
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在深度学习中,loss的大小通常用来衡量模型的训练效果和优化目标的达成程度。loss的大小取决于具体的损失函数和训练数据。不同的损失函数有不同的计算方式和目标,因此loss的大小也会有所不同。 引用\[1\]中提到了一些常见的损失函数,如Focal Loss、IOU Loss、Softmax Loss等。这些损失函数在目标检测、分类和分割等任务中被广泛使用。其中,Focal Loss主要用于解决目标检测中正负样本比例失衡的问题,IOU Loss用于衡量预测框与真实框之间的重叠程度,Softmax Loss用于分类任务。 由于不同的损失函数具有不同的计算方式和目标,因此它们的loss大小也会有所不同。一般来说,loss的大小越小表示模型的拟合程度越好,即模型对训练数据的预测结果与真实标签更接近。但是,具体的loss大小还需要结合具体的任务和数据集来进行分析和解释。 总之,深度学习中loss的大小是衡量模型训练效果和优化目标达成程度的重要指标,不同的损失函数和任务会导致不同的loss大小。 #### 引用[.reference_title] - *1* *2* *3* *5* [深度学习基础loss和目标检测loss总结](https://blog.csdn.net/qq_36523492/article/details/112789110)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *4* [深度学习——知识点总结3(损失函数Loss)](https://blog.csdn.net/baobei0112/article/details/95060370)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑猫大人-魏盛楠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值