mui热更新

2017-11-15  本文已影响845人  没有昵_称
 plus.runtime.getProperty(plus.runtime.appid,function(inf){                                 
    console.log(inf.version);  //当前安装包的version                                                                       
  });
 var options = {method:"GET"};
 dtask = plus.downloader.createDownload( url, options );
 dtask.addEventListener( "statechanged", function(task,status){             
    switch(task.state) {
            case 1: // 开始
                console.log( "开始下载..." );
            break;
            case 2: // 已连接到服务器
                console.log( "链接到服务器..." );
            break;
            case 3: // 已接收到数据                                
                var a= Math.floor(task.downloadedSize/task.totalSize*100)+'%';
                document.getElementById('two').style.width=a
                
            break; 
            case 4: // 下载完成
                console.log( "下载完成!" );                                                                     
                install (task)
            break;
        }
 } );
dtask.start();  
function install (task){
      plus.runtime.install(task.filename, {force:true}, function() {
        //完成更新向服务器进行通知
        alert("更新完毕,将重启应用!");
        plus.runtime.restart();
     },function(err){
        alert(JSON.stringify(err));
        mui.toast("安装升级失败");
   });
}

image.png
上一篇 下一篇

猜你喜欢

热点阅读