mui -检测用户手机app上的版本-自动更新

    //获取版本号提示更新
        var btn = ["确定升级", "取消"];
//获取app系统更新[是否手动点击获取更新]
function appUpdate(ismanual) {
    console.log('appUpdate');
    var banbenid=1;
    
    mui.plusReady(function () {
        plus.runtime.getProperty(plus.runtime.appid, function (inf) {
            ver = inf.version;
            console.log('手机版本ver:' + ver);
            var client;
            var ua = navigator.userAgent.toLowerCase();
            if (/iphone|ipad|ipod/.test(ua)) {    //苹果手机            
                mui.ajax(url+"/front_get_bybneben.do?id="+banbenid,{
                    type: "GET",
                    async:false,
                    dataType: "jsonp",
                    success: function (data) {
                        //console.log('data:' + JSON.stringify(data));
                        var resultCount = data.list.banben;
                        //console.log(resultCount);
                    
                            if (resultCount > ver) {
                                var _msg = "发现新版本:V" + resultCount;
                                //plus.nativeUI.alert("发现新版本:V" + normItem);
                                mui.confirm(_msg, '升级确认', btn, function (e) {
                                    if (e.index == 0) { //执行升级操作
                                        document.location.href = 'http://******/HibuddyApp.apk'; //上新APPStore下载地址
                                    }else if(e.index == 1){
                                        plus.runtime.quit();
                                    }
                                });
                                return;
                            } 
                        
                        if (ismanual) {
                            mui.toast('当前版本号已是最新');
                        }
                        return;
                    }
                });
            } else if (/android/.test(ua)) {
                mui.ajax(url+"/front_get_bybneben.do?id="+banbenid,{
                    type: "GET",
                    async:false,
                    dataType: "jsonp",
                    success: function (data) {
                       // console.log('data:' + JSON.stringify(data));
                        var json_data = jQuery.parseJSON(data);
                        var resultCount = json_data.list.banben;
                        console.log(resultCount);
                    /* if (resultCount > ver) {
                                var _msg = "发现新版本:V" + resultCount;
                                //plus.nativeUI.alert("发现新版本:V" + normItem);
                                mui.confirm(_msg, '升级确认', btn, function (e) {
                                    if (e.index == 0) { //执行升级操作
                                        document.location.href = 'http://*****/HibuddyApp.apk'; //上新APPStore下载地址
                                    }else if(e.index == 1){
                                        plus.runtime.quit();
                                    }
                                });
                                return;
                            } 
                            if (ismanual) {
                            mui.toast('当前版本号已是最新');
                        }
                            return;
                       },*/
                      var apkUrl = "http://114*****uddy/HibuddyApp.apk";
                       if (resultCount > ver) {
                            //mui.toast("发现新版本:V" + data.Data);//获取远程数据库中上新andriod版本号 
                            var _msg="发现新版本:V" + resultCount;
                            mui.confirm(_msg, '升级确认', btn, function (e) {
                                if (e.index == 0) { //执行升级操作
                                    plus.nativeUI.toast("正在准备环境,请稍后!");
                                    var dtask = plus.downloader.createDownload(apkUrl, {}, function (d, status) {
                                        if (status == 200) {
                                            var path = d.filename;//下载apk
                                            plus.runtime.install(path); // 自动安装apk文件
                                        } else {
                                            plus.nativeUI.alert('版本更新失败:' + status);
                                        }
                                    });
                                    dtask.start();
                                }else if(e.index == 1){
                                        plus.runtime.quit();
                                    }
                            });
                        } else {
                            console.log('当前版本号已是最新');
                            if (ismanual) {
                                mui.toast('当前版本号已是最新');
                            }
                            return;
                        }
                    },
                   
                    error: function (xhr, type, errerThrown) {
                        if (ismanual) {
                            mui.toast('网络异常,请稍候再试');
                        }
                    }
                });
            }
        });
    });
}

 ajax访问的是从后台数据库传来的一个版本号(这个版本号是开发者自己手动输入上去)每次升级,需要自己改动版本号

而手机上的版本号是开发者平台打包时,配置的必填项;

需要在数据库见一个存放版本号的表

查询出来的版本号与手机版本号相对比

 

转载于:https://www.cnblogs.com/fdxjava/articles/11475071.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值