直接上代码吧,你竟然搜到了我的文章就应该知道了,为什么要热更新

//app热更新下载
//假定字符串的每节数都在5位以下
function toNum(a) {
//也可以这样写 var c=a.split(/\./);
var c = a.split('.');
var num_place = ["", "0", "00", "000", "0000"],
r = num_place.reverse();
for(var i = 0; i < c.length; i++) {
var len = c[i].length;
c[i] = r[len] + c[i];
}
var res = c.join('');
return res;
} var btn = ["确定升级", "取消"];
//获取app系统更新[是否手动点击获取更新]
function appUpdate(Index) {
console.log('appUpdate');
mui.plusReady(function() {
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
ver = inf.version + '';
console.log('ver:' + ver);
var client;
var ua = navigator.userAgent.toLowerCase();
if(/iphone|ipad|ipod/.test(ua)) { //苹果手机
mui.ajax({
type: "get",
dataType: 'json',
url: "https://itunes.apple.com/lookup?id=1462614850", //获取当前上架APPStore版本信息
data: {
id: 1462614850 //APP唯一标识ID
},
contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
success: function(data) {
console.log('data:' + JSON.stringify(data));
var resultCount = data.resultCount;
for(var i = 0; i < resultCount; i++) {
var normItem = data.results[i].version;
console.log('normItem:' + normItem)
if(normItem > ver) {
var _msg = "发现新版本:V" + normItem;
//plus.nativeUI.alert("发现新版本:V" + normItem);
mui.confirm(_msg, '升级确认', btn, function(e) {
if(e.index == 0) { //执行升级操作
document.location.href = 'https://itunes.apple.com/cn/app/%E5%AD%A9%E5%84%BF%E6%AC%A2/id1462614850?mt=8'; //上新APPStore下载地址
}
});
return;
}
}
if(ismanual) {
mui.toast('当前版本号已是最新');
}
return;
}
});
} else if(/android/.test(ua)) {
mui.ajax(ip + "APIVApp/SelectVApp", {
data: {
apkVersion: ver,
},
dataType: 'json',
type: 'get',
timeout: 10000,
success: function(data) {
console.log('data:' + JSON.stringify(data))
console.log(toNum(ver))
if(toNum(data[0]._vname) > toNum(ver)) {
var _msg = "发现新版本:V" + data[0]._vname;
mui.confirm(_msg, '升级确认', btn, function(e) {
if(e.index == 0) { //执行升级操作
downWgt();
}
});
} else {
console.log(Index);
if(Index) {
mui.toast('当前版本号已是最新');
}
return;
}
},
error: function(xhr, type, errerThrown) {
mui.toast('网络异常,请稍候再试');
}
});
}
});
});
} // 下载wgt文件
function downWgt() {
var wgtUrl = ip + "app/H5750CDB5.wgt";
plus.nativeUI.showWaiting("下载更新文件...");  
plus.downloader.createDownload(wgtUrl, {
filename: "_doc/update/"
}, function(d, status) {    
if(status == 200) {       
console.log("下载更新文件成功:" + d.filename);      
installWgt(d.filename); //安装wgt包
    
} else {      
console.log("下载失败!");      
plus.nativeUI.alert("下载失败!");    
}    
plus.nativeUI.closeWaiting();  
}).start();
} function installWgt(path) {  
plus.nativeUI.showWaiting("安装更新文件...");  
plus.runtime.install(path, {}, function() {    
plus.nativeUI.closeWaiting();    
console.log("安装更新文件成功!");    
plus.nativeUI.alert("应用资源更新完成!", function() {      
plus.runtime.restart();    
});  
}, function(e) {    
plus.nativeUI.closeWaiting();    
console.log("安装更新文件失败[" + e.code + "]:" + e.message);    
plus.nativeUI.alert("安装更新文件失败[" + e.code + "]:" + e.message);    
if(e.code == 10) {    
alert('请清除临时目录');    
}  
});
}
05-11 22:42