zoukankan      html  css  js  c++  java
  • 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);
            }
        }); */
  • 相关阅读:
    新发地突发新冠病例,我从北京来赶来为疾控软件开发人员分享Azure DevOps,汗
    Azure DevOps Server:还原被删除的分支
    Azure DevOps Server 拉取请求模板(Pull Request Template)
    Azure DevOps Server:使用Postman批量删除测试用例
    Visual Studio Code:在操作系统文件夹或文件上出现Open with Code菜单
    在Windows XP上访问Azure DevOps Server 2019(TFS)
    将团队项目迁移到另外一个团队项目集合中
    快速排序c++实现 快排C++代码实现
    高等代数(第四版) 王萼芳课后答案
    数据结构题集(C语言版)课后答案+源码严蔚敏、吴伟民编著
  • 原文地址:https://www.cnblogs.com/Dark-fire-liehuo/p/10730025.html
Copyright © 2011-2022 走看看