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("下载升级文件",{width:'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); } }); */