zoukankan      html  css  js  c++  java
  • mui项目实时更新

    var wgtVer=null;
    function plusReady(){
    // ......
    // 获取本地应用资源版本号
    plus.runtime.getProperty(plus.runtime.appid,function(inf){
    wgtVer=inf.version;
    console.log("当前应用版本:"+wgtVer);
    banben()

    });
    }
    // 进入首页更新
    if(window.plus){
    plusReady();
    }else{
    document.addEventListener('plusready',plusReady,false);
    }
    //检测版本
    var num=parseInt(Math.random()*1000);
    function banben(){
    var banurl="http://cdn.brain-info.top/saima.json?v="+num;
    try{
    mui.ajax(banurl,{
    dataType:'json',//服务器返回json格式数据
    type:'get',//HTTP请求类型
    timeout:10000,//超时时间设置为10秒;
    success:function(data){
    if(data.version!=wgtVer){
    downWgt()
    }
    },
    error:function(xhr,type,errorThrown){
    }
    });
    }catch(e){
    }
    }

    // 下载wgt文件
    var wgtUrl="http://cdn.brain-info.top/saima.wgt?="+num;
    function downWgt(){
    plus.nativeUI.showWaiting("应用更新中...");
    plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
    if ( status == 200 ) {
    console.log("下载wgt成功:"+d.filename);
    installWgt(d.filename); // 安装wgt包
    } else {
    console.log("下载wgt失败!");
    plus.nativeUI.alert("应用更新失败!");
    }
    plus.nativeUI.closeWaiting();
    }).start();
    }
    //更新应用资源包(wgt文件)
    function installWgt(path){
    plus.nativeUI.showWaiting("应用安装中...");
    plus.runtime.install(path,{},function(){
    plus.nativeUI.closeWaiting();
    console.log("安装wgt文件成功!");
    plus.nativeUI.alert("应用资源安装完成!",function(){
    plus.runtime.restart();
    });
    },function(e){
    plus.nativeUI.closeWaiting();
    console.log("安装wgt文件失败["+e.code+"]:"+e.message);
    plus.nativeUI.alert("安装应用失败["+e.code+"]:"+e.message);
    });
    }

  • 相关阅读:
    HP惠普战66电源黄灯闪烁无法充电
    C#.NET rabbit mq 持久化时报错 durable
    手动解压安装mysql8.0 on windows my.ini
    C#.NET MySql8.0 EF db first
    EF MYSQL 出现:输入字符串的格式不正确
    EF MYSQL DB FIRST 出现2次数据库名
    mysql windows 下配置可远程连接
    团队项目的Git分支管理规范
    一个简单的软件测试流程
    微服务架构下的质量迷思——混沌工程
  • 原文地址:https://www.cnblogs.com/wrong930803/p/9295175.html
Copyright © 2011-2022 走看看