uniapp 安卓检测版本更新

   

onLoad() {
    //检测更新
   this.updateVersion();
  },
updateVersion() {

      console.log("检查更新》》》》》》》》》》》》》》");

      plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {

        let sysInfo;

        uni.getSystemInfo({

          success: function (res) {

            sysInfo = res;

          },

        });

      
       //sysInfo.appVersion 为当前应用版本号
        this.api.request( "xxx/xxxx/xxxx?versionNo=" +

     sysInfo.appVersion, null,"get")

          .then((res) => {

            let that = this;

            let resource = res;

            if (res.code == 200) {

              uni.showModal({

                title: "更新提示",

                showCancel: false,

                confirmText: "确定更新", //只保留确定更新按钮

                content: "检测到新版本,需要下载新版本的应用程序",

                success: function (res) {

                  if (res.confirm) {

                    uni.showLoading({

                      title: "正在更新...",

                    });

                    console.log(resource);

                    //下载地址根据实际来修改,我这个是拼接前缀的下载地址

                    let downUrl =

                      that.api.baseUrl + resource.data.downloadAddress;

                    console.log("url:" + downUrl);

                    uni.downloadFile({

                      url: downUrl,

                      success: function (downloadResult) {

                        if (downloadResult.statusCode == 200) {

                          plus.runtime.install(

                            downloadResult.tempFilePath,

                            {

                              force: false,

                            },

                            function () {

                              uni.hideLoading();

                              uni.showModal({

                                confirmText: "重启应用", //只保留确定更新按钮

                                content: "应用更新完成!",

                                showCancel: false,

                                success: function (res) {

                                  console.log(res);

                                  if (res.confirm) {

                                    console.log("安装成功");

                                    plus.runtime.restart();

                                  }

                                },

                              });

                            },

                            function (e) {

                              uni.hideLoading();

                              console.log(e);

                              console.log("安装失败...");

                            }

                          );

                        }

                      },

                    });

                  }

                },

              });

            } else {

              console.log("已经是最新版本,无需更新");

            }

          });

      });

    },

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值