整包更新
与热更新不同,整包更新比对的版本号是应用版本名称
//检测当前版本号
dqbanben:function(){
var that=this;
//在页面中初始化plus插件
mui.init();
mui.plusReady(function(){
// 获取本地应用资源版本号
that.wgtVer= plus.runtime.version;
that.checkUpdate();
});
},
//检查更新
checkUpdate:function(){
var that=this;
this.$http.post(this.GLOBAL.host+'/version/checkUpdate', {
version:that.wgtVer
})
.then(function (res) {
if(res.data.code==0){
if(res.data.result==1){//跟后台传过来的版本号比对,如果版本号不一致
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //如果是苹果手机
plus.nativeUI.confirm("检测到有新版本,是否更新",function(e){
if(e.index==0){ //如果选择更新
window.location.href="itms-services://?action=download-manifest&url=https://ios.17rua.top/static/ios/x5.plist";
//不经过苹果商店下载(不懂得看我的另一篇文章)
plus.nativeUI.showWaiting("正在下载...");
}
},"",["立即更新","以后再说"]);
return;
}else{
plus.nativeUI.confirm("检测到有新版本,是否更新",function(e){
if(e.index==0){
that.downWgt(res.data.url);//下载文件
}else{
plus.runtime.quit();//安卓控制不更新退出应用
}
},"",["立即更新","以后再说"]);
}
sessionStorage.setItem('kbj_banben',true);//检验过一次版本就加入缓存,不在检测
}else{
sessionStorage.setItem('kbj_banben',true);
return;
}
}else{
alert("获取数据失败")
}
})
.catch(function (error) {
alert("请检查网络连接")
});
},
//下载资源包
downWgt:function(wgtUrl){
var that=this;
var task=plus.downloader.createDownload( wgtUrl, {}, function(download,status){ //安装到手机的目录
if ( status == 200 ) {
plus.runtime.install(download.filename); // 安装下载的apk文件
// that.installWgt(d.filename); // 安装wgt包
} else {
//console.log("下载wgt失败!");
mui.toast("下载更新失败!");
plus.nativeUI.closeWaiting();
}
});
task.addEventListener("statechanged", function (download, status) {
switch (download.state) {
case 2:
plus.nativeUI.showWaiting("正在下载...");
break;
case 3:
that.percent = download.downloadedSize / download.totalSize * 100;
// 下载进度 可以根据情况显示
break;
case 4:
mui.toast("下载完成");
plus.nativeUI.closeWaiting();
break;
}
});
task.start();
},
这样就可以实现ios与安卓的整包更新,而且IOS不用经过应用商店更新。