MUI在线升级APP

function checkUpdate_wgt(){
  var version ;
  plus.runtime.getProperty(plus.runtime.appid,function(inf){
  version = inf.version;
//console.log("获取本地应用资源版本号:"+inf.version);
mui.ajax('http://XXX/ajax/update.asmx/appcheck_wgt',{
data:JSON.stringify( { version: version,package:"MgooGps"}),
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},              
success:function(res){
res = JSON.parse(res.d);
if (res.StatusCode == 200) {
//有新版本
console.log(res.Message);
downWgt(res.Result);

},
error:function(xhr,type,errorThrown){
//异常处理;
//console.log(type);
}
});
});
 
/* D:\MgooInterface\update\MgooGps*/
  /*var wgtver =null;
  plus.runtime.getProperty(plus.runtime.appid,function(Inf){
  console.log(Inf.version);
  wgtver=Inf.version;
  console.log(wgtver);
  /*mui.alert("当前版本"+wgtver); 
  localStorage.setItem("Version",wgtver);
  });*/
  
}


function downWgt(url) {
//var url='http://XXX/update/update.wgt';
   console.log("checkupdate....");
   console.log(url);  
   var dtask = plus.downloader.createDownload( url, {method:"GET"}, function(d,status){ 
    console.log(status);
    //console.log(status);
       if ( status == 200 ) { 
           console.log("下载成功 " + d.filename ); 
           plus.runtime.install(d.filename,{},function(){
            console.log(d.filename + "install success....");
            if (d.filename.indexOf(".apk") >= 0) {
            plus.nativeUI.closeWaiting();
            plus.nativeUI.alert("安装成功是否重启",function(){
                  plus.runtime.restart();
                });
           
               //plus.runtime.restart();
           },function(e){
            console.log("install error....");
            if (d.filename.indexOf(".apk") >= 0) {
            mui.alert("安装失败:"+e.message);
            }
               //plus.nativeUI.closeWaiting();
               //alert("安装失败: "+e.message);
           });
       } else {
        console.log("download error....");
           //plus.nativeUI.closeWaiting();
          // alert( "下载失败: " + status ); 
       } 
   } );      
   dtask.addEventListener('statechanged',function(d,status){
       //console.log("statechanged: "+d.state);
   });
   dtask.start();
}



function checkUpdate_apk (showWaiting) {
if (mui.os.android) {
if (showWaiting) { 
plus.nativeUI.showWaiting("检测更新...");
}
plus.runtime.getProperty(plus.runtime.appid,function(inf){
  var version = inf.version;
  mui.ajax('http://XXXX/ajax/update.asmx/appcheck_apk',{
data:JSON.stringify({ version: version,package:"MgooGps"}),
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},              
success:function(res){
plus.nativeUI.closeWaiting();
res = JSON.parse(res.d);
if (res.StatusCode == 200) {
//有新版本 
console.log(res.Message);
mui.confirm('检测到新版本,是否更新?','提示',['取消','确认'],function (e) {
if(e.index == 1){
plus.nativeUI.showWaiting("正在下载...");
downWgt(res.Result);
}
},'div') 
}else{
if (showWaiting) {
plus.nativeUI.toast(res.Message);
}
}
},
error:function(xhr,type,errorThrown){
//异常处理;
//console.log(type);
}
});
  }); 
}else if(mui.os.ios){
//ios 需要跳转到AppStore更新
/* var url='itms-apps://itunes.apple.com/cn/app/hello-h5+/id682211190?l=zh&mt=8';// HelloH5应用在appstore的地址
plus.runtime.openURL(url);*/
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值