• app每次更新版本时调用js代码提示用户下载更新


    var url = '网络地址';
    //APP升级
    var wait;
    function update(){
        //判断操作系统
        var system = 'android';
        if(mui.os.ios){
            system = 'ios';
        } 
        mui.getJSON(url+'/apicommon/update/index',{
                app:'cooperatives',
                system:system,
                version:plus.runtime.version
            },function(data){
                //data = JSON.stringify(data);
                if(data.code==200){
                    var APPInfo = data.data;
                    if(APPInfo.colum=='full'){
                        mui.confirm(APPInfo.brief, APPInfo.name, ['稍后','立即升级'], function(e) {
                            if(e.index==1){
                                if(system=='android'){
                                    //当苹果调整进市场下载
                                    plus.runtime.openURL(APPInfo.url);  
                                    plus.nativeUI.closeWaiting();
                                }else{
                                    wait = plus.nativeUI.showWaiting("下载升级文件",{'100%',height:'100%',round:0,background:'rgba(0,0,0,0.3)'});
                                    //当安卓及其他下载
                                    var dtask = plus.downloader.createDownload(url+APPInfo.url, {}, function(d, status){
                                        if(status == 200){ 
                                            console.log(d.filename);
                                            wait.setTitle("安装APP更新");
                                            plus.runtime.install(d.filename,{},function(){  
                                                plus.nativeUI.closeWaiting();
                                                mui.alert('应用安装完成', '升级成功', '确认重启', function(e) {
                                                    plus.runtime.restart();
                                                });
                                                delFile(d.filename);
                                            },function(e){  
                                                plus.nativeUI.closeWaiting(); 
                                                mui.toast('安装失败');
                                                delFile(d.filename);
                                            });
                                        } else {
                                            plus.nativeUI.closeWaiting();
                                            mui.toast('下载失败');
                                        }  
                                    });
                                    dtask.addEventListener("statechanged", onStateChanged, false);
                                    dtask.start();
                                }
                            }
                        });
                    }else{
                        var dtask = plus.downloader.createDownload(url+APPInfo.url, {}, function(d, status){
                            if(status == 200){
                                plus.runtime.install(d.filename,{},function(){  
                                    delFile(d.filename);
                                },function(e){ 
                                    delFile(d.filename);
                                });
                            } 
                        });
                        dtask.start();
                    }
                    //plus.navigator.closeSplashscreen();
                }
        });
    }
    function onStateChanged(download, status) {
        wait.setTitle((download.downloadedSize/(1024 * 1024)).toFixed(2)+'MB/'+(download.totalSize/(1024 * 1024)).toFixed(2)+'MB');
    }
    function delFile(filename) {
        plus.io.resolveLocalFileSystemURL(filename, function(entry) {
            entry.remove();
        });
    }
    
    //打开新窗口
    function opens(url,data){
        mui.openWindow({
            url:url, 
            id:url,
            waiting:{
                autoShow:false,
            },
            show:{
              aniShow:"pop-in"
            },
            extras:data
        });
    }
    //登录窗口
    function login_open(url,data){
        mui.openWindow({
            url:url, 
            id:url,
            waiting:{
                autoShow:false,
            },
            show:{
              aniShow:"slide-in-bottom"
            },
            extras:data
        });
    }
    //登录窗口
    function search_open(url,data){
        mui.openWindow({
            url:url, 
            id:url,
            waiting:{
                autoShow:false,
            },
            show:{
              aniShow:"none"
            },
            extras:data
        });
    }
    //监听状态栏
    mui.ready(function() {});
    mui.plusReady(function() {});
    
    
    
    
    /* mui.ajax(url+'apicommon/update/index',{
            data:{
                app:'cooperatives',
                system:'ios',
                version:plus.runtime.version
            },
            dataType:'json',//服务器返回json格式数据
            type:'post',//HTTP请求类型
            success:function(data){
                console.log('加载:3');
                response = JSON.stringify(data);
                console.log('加载:'+response);
                plus.navigator.closeSplashscreen();
            },
            error:function(xhr,type,errorThrown){
                //异常处理;
                console.log('异常:'+type);
            }
        }); */
  • 相关阅读:
    面试总结
    回溯-递归练习题集
    2018年度业余学习总结
    12306余票高效查询--clojure实现
    Mac中wireshark如何抓取HTTPS流量?
    2017年学习总结
    Clojure——学习迷宫生成
    新生帝之2016年的计划,努力去做好!
    EmitMapper
    ASP.NET 修改地址返回图片缩率图
  • 原文地址:https://www.cnblogs.com/Dark-fire-liehuo/p/10730025.html
Copyright © 2020-2023  润新知