zoukankan      html  css  js  c++  java
  • hubilder热更新

      <script type="text/javascript">
        
            function plusReady(){
                plus.key.addEventListener('backbutton',function(){
                    if(confirm('确认退出?')){
                        plus.runtime.quit();
                    }
                },false);
                
                var checkUrl="http://xxxxxx/version.txt";
                plus.runtime.getProperty(plus.runtime.appid,function(inf){
                    var wgtVer = inf.version;
                    console.log("当前应用版本:"+wgtVer); 
                    var xhr=new XMLHttpRequest();
                    xhr.onreadystatechange=function(){
                        switch(xhr.readyState){
                            case 4:
                                plus.nativeUI.closeWaiting();
                                if(xhr.status==200){
                                    var newVer=xhr.responseText;
                                    console.log("检测更新成功:"+newVer);
                                    if(newVer.toString().substr(0,5) == wgtVer.toString().substr(0,5)){
                                        console.log("无新版本可更新!")
    //                                    plus.nativeUI.alert("无新版本可更新!");
                                    }else{
                                        downWgt();    // 下载升级包
                                        console.log("正在更新")
                                    }
                                }else{
                                    console.log("检测更新失败!");
                                    plus.nativeUI.alert("检测更新失败!");
                                }
                            break;
                            default:  
                            break; 
                        }
                    }
                    xhr.open('GET',checkUrl);
                    xhr.send();
                });
                
            }
            
            if(window.plus){
                plusReady();
            }else{
                document.addEventListener('plusready',plusReady,false);
            }
            
            // 下载wgt文件
            var wgtUrl="http://xxxxxx/update.wgt";
            function downWgt(){
                plus.nativeUI.showWaiting("下载wgt文件...");
                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("下载wgt失败!"); 
                    }
                    plus.nativeUI.closeWaiting();
                }).start();
            }
            // 更新应用资源
            function installWgt(path){
                plus.nativeUI.showWaiting("安装wgt文件...");
                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("安装wgt文件失败["+e.code+"]:"+e.message);
                });
            }
    
        </script>
  • 相关阅读:
    day49 前端之 jQery
    day48 BOM DOM jQuery
    如何用命令将本地项目上传到git---转
    jenkins邮件通知
    shell文件管理jenkins构建过程---window环境下报错:找不到shell文件
    【转】adb shell am instrument 命令详解
    INSTRUMENTATION_STATUS_CODE: -1,Error=Unable to find instrumentation info for
    Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
    【转】Java基础知识总结
    查看apk包名和Activity的方法
  • 原文地址:https://www.cnblogs.com/wrongcode/p/11765188.html
Copyright © 2011-2022 走看看