zoukankan      html  css  js  c++  java
  • APP版本更新功能

    基于Hbuilder、mui 新增APP版本更新功能

    参考地址: HBuilder打包成apk之后,如何让版本检测自动更新

    //检查版本并更新
    function checkversion(){
        mui.ajax(mui.check.url, {//需要从接口中获取最新版本信息,与当前版本比较,确认是否是最新版本
            data: {
                'token': mui.check.token,
                'module': 'template',
                'action': 'checkVersion'
            },
            dataType: 'json',
            type: 'post',
            headers: {
                'Content-Type': 'application/json'
            },
            success: function(res) {
                if (res.status != 0) {
                    plus.runtime.getProperty(plus.runtime.appid,function(inf){
                        if(inf.version != res.data.version){
                            var _msg = "主人,有更强大的新版本了!";
                            mui.confirm(_msg, '更新提醒', ["立即更新","稍后更新"], function (e) {
                                if (e.index == 0) {
                                    if(mui.os.ios){//区分ios和Android平台
                                        document.location.href = res.data.downloadurl;//上新APPStore下载地址
                                        // https://itunes.apple.com/cn/app/san-gu-hui/id131812xxxx?mt=8
                                    }else{
                                        plus.nativeUI.toast("正在准备环境,请稍后!");
                                        var dtask = plus.downloader.createDownload(res.data.downloadurl, {}, function (d, status) {
                                            if (status == 200) {
                                                var path = d.filename;//下载apk
                                                plus.runtime.install(path); // 自动安装apk文件
                                            } else {
                                                plus.nativeUI.alert('版本更新失败:' + status);
                                            }
                                        });
                                        dtask.start();
                                    }
                                }
                            });
                        }else{
                            //console.log('已是最新版本');
                        }
                    });
                }
            }
        });
    }
    //接口返回数据示例:data.setting:{"version":"1.1.13","downloadurl":"https://itunes.apple.com/cn/app/san-gu-hui/id131812xxxx?mt=8"}
  • 相关阅读:
    sys模块详解
    os模块详解2
    tyvj 1203 机器分配
    洛谷 P1496 火烧赤壁
    P1204 [USACO1.2]挤牛奶Milking Cows
    bzoj 2120 数颜色
    P2056 采花
    P1972 [SDOI2009]HH的项链
    9.20模拟赛
    P2709 小B的询问
  • 原文地址:https://www.cnblogs.com/mengwangchuan/p/9604102.html
Copyright © 2011-2022 走看看