1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- var _config = {url : 'http://58.244.255.94/trs_data/'}
- var checkUrl= _config.url + "trsdataAction!checkUpdate.action";
- //需要传递当前的版本
- function checkUpdate( wgtVer ){
- plus.nativeUI.showWaiting("检测更新...");
- mui.ajax( checkUrl , { dataType : "json", type : 'POST',
- data : {ver : wgtVer},
- success : function(json){
- plus.nativeUI.closeWaiting();
- if( json.success ==true ){
- //可以升级
- plus.nativeUI.confirm("检测到更新的版本,是否下载升级?",
- function(event){
- if(event.index ==0){
- console.log('下载地址:'+_config.url + json.url)
- downWgt(_config.url + json.url); //下载更新版的地址
- }
- } ,'系统消息',['马上升级','下次再说']);
- } else{
- plus.nativeUI.toast("无新版本可更新!");
- }
- },
- error : function(xhr, error){
- plus.nativeUI.closeWaiting();
- plus.nativeUI.toast('检测更新失败!') ;
- }
- }) ;
- }
- // 下载wgt文件
- function downWgt(wgtUrl){
- 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();
- }
- // 更新应用资源
- function installWgt(path){
- plus.nativeUI.showWaiting("安装更新文件...");
- plus.runtime.install(path,{},function(){
- plus.nativeUI.closeWaiting();
- plus.nativeUI.alert("应用资源更新完成!",function(){
- plus.runtime.restart();
- });
- },function(e){
- plus.nativeUI.closeWaiting();
- plus.nativeUI.alert("安装更新文件失败["+e.code+"]:"+e.message);
- });
- }
|