zoukankan      html  css  js  c++  java
  • uni-app 版本更新控制

    1、app.vue: app加载时候,获取app版本号

    //获取版本号
    plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
        uni.setStorage({
            key: 'wgtinfoVersionCode',
            data: wgtinfo.versionCode
        })
    })

    2、index:首页页面加载时,获取后端返回的app版本号

    getSysVersion() {
        const _this = this;
      //获取缓存中,当前app的版本号 uni.getStorage({ key:
    'wgtinfoVersionCode', success: (res) => { this.wgtinfoVersionCode = res.data; uni.request({ url: this.$url + '/sysNotice/querySysVersion', //后端接口 method: 'post', sslVerify: false,//不验证ssl证书 success: res => { console.log(res.data.data, this.wgtinfoVersionCode); if(res.statusCode == 200) {
                  //后端返回的app版本和当前app版本比较
    if(Number(res.data.data) != Number(this.wgtinfoVersionCode)) { // this.showModal = true; uni.showModal({ title: "发现新版本", content: "确认下载更新", success: (res) => { if (res.confirm == true) {//当用户确定更新,执行更新 _this.appdownLoad(); } } }) } } }, fail: err => { console.log(err) this.$api.msg('请求错误!'); this.logining = false; }, }); } }) },

    3、执行下载app:

    appdownLoad(){
        var that = this;
        uni.showLoading({
            title: '安装包下载中……'
        })
        const downloadTask = uni.downloadFile({
            url: 'http://XXXXXXXXXXXX.apk', //服务器 app 的下载地址
            success: (downloadResult) => {
                uni.hideLoading();
                if (downloadResult.statusCode === 200) {
                    uni.showModal({
                        title: '',
                        content: '下载成功,是否允许安装新版本?',
                        confirmText: '确定',
                        success: function(res) {
                            if (res.confirm == true) {
                                plus.runtime.install(//安装
                                    downloadResult.tempFilePath, {
                                        force: true
                                    },
                                    function(res) {
                                        utils.showToast('更新成功,重启中');
                                        plus.runtime.restart();
                                    }
                                );
                            }
                        }
                    });
                }
            }
        });
    },

    附图:

          

       

  • 相关阅读:
    JAVA网络编程-客户端Socket
    JAVA网络编程-URLConnection
    React Native push操作
    Mac电脑输入特殊符号
    iOS sizeForItemAtIndexPath方法在iOS14下变化
    iOS NSDictionary与模型(JSONModel、YYModel)的对比
    iOS UICollectionView实现动态标签(单选、多选)
    iOS Masonry 使用小记(MASConstraint、center、centerX、edges、equalTo、greaterThanOrEqualTo)
    linux上搭建 python虚拟环境
    linux进程和线程查看
  • 原文地址:https://www.cnblogs.com/moguzi12345/p/14498351.html
Copyright © 2011-2022 走看看