var wgtVer = null;
function plusReady() {
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
wgtVer = inf.version;
console.log("当前应用版本:" + wgtVer);
checkUpdate();
});
}
if(window.plus) {
plusReady();
} else {
document.addEventListener('plusready', plusReady, false);
}
// 检测更新
var checkUrl = "http://wechat.wisdomitservices.cn/mobile/update.php";
function checkUpdate() {
plus.nativeUI.showWaiting("检测更新...");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
switch(xhr.readyState) {
case 4:
plus.nativeUI.closeWaiting();
if(xhr.status == 200) {
console.log("检测更新成功:" + xhr.responseText);
var newVer = xhr.responseText;
if(wgtVer && newVer && (wgtVer != newVer)) {
downWgt(); // 下载升级包
} else {
plus.nativeUI.toast("无新版本可更新!");
}
} else {
console.log("检测更新失败!");
plus.nativeUI.toast("检测更新失败!");
}
break;
default:
break;
}
}
xhr.open('GET', checkUrl);
xhr.send();
}
// 下载wgt文件
var wgtUrl = "http://wechat.wisdomitservices.cn/mobile/update/H506EF261.wgt";
function downWgt() {
plus.nativeUI.showWaiting("下载wgt文件...");
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("下载wgt失败!");
}
plus.nativeUI.closeWaiting();
}).start();
}
// 更新应用资源
function installWgt(path) {
plus.nativeUI.showWaiting("安装wgt文件...");
plus.runtime.install(path, {}, function() {
plus.nativeUI.closeWaiting();
console.log("安装wgt文件成功!");
plus.nativeUI.alert("应用资源更新完成!", function() {
plus.runtime.restart();
});
}, function(e) {
plus.nativeUI.closeWaiting();
console.log("安装wgt文件失败[" + e.code + "]:" + e.message);
plus.nativeUI.alert("安装wgt文件失败[" + e.code + "]:" + e.message);
});
}
参考 http://cache.baiducontent.com/c?m=9d78d513d99c06f44fede53b5850c0666808dd252bd7a14668d4e200c8264c413635a3ea7d795453c7823c390ef50f1aa8e737012a1e73f6c2df883d8beacc7568de30340740d10705d36efe975b768166cb0bb7f804e4b0f0&p=882a9645d69f14f20be296204a0a93&newp=882a9645d69f52fc57efcc624f4886231610db2151d4db106b82c825d7331b001c3bbfb42323140fd4cf7b6203af435aedf03c74360421a3dda5c91d9fb4c57479d434&user=baidu&fm=sc&query=mui+wgt+not+a+zip+archive&qid=bca7487300023f53&p1=2#baidusnap5
更新时提示
安装wgt文件失败[10]:Not a zip archive
1 个回复
wclssdn
自己再加一个文件md5校验~ 确保文件下载过程中不出错~