/*
* 静默更新插件
* 直接appUpadata.init()去调用此插件
*/
! function(window, undefined) {
var appUpdata = window.appUpdata = {
init: function() {
var that = this;
if(plus) {
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
var wgtVer = inf.version;
bpAjax("此处为利用ajax请求服务器的静默更新版本,后台返回一个下载地址", {
version: plus.runtime.version,
resVersion: wgtVer
}, function(d) {
that.downFn(d.data.url);
}, function(d) {
//mui.toast(d.info)
}, 1, "版本")
});
}
},
// 下载文件
downFn: function(wgtUrl) {
var that = this;
if(plus) {
plus.downloader.createDownload(wgtUrl, {
filename: "_doc/update/"
}, function(d, status) {
if(status == 200) {
that.installWgt(d.filename);
} else {
console.log("下载版本失败!");
}
}).start();
}
},
// 安装文件
installWgt: function(path) {
if(plus) {
plus.runtime.install(path, {}, function() {
console.log("安装版本成功!");
}, function(e) {
console.log("安装版本失败[" + e.code + "]:" + e.message);
});
}
}
}
}(window)

前端攻城师
- 发布:2017-10-25 17:48
- 更新:2019-08-14 17:10
- 阅读:2404
【分享】静默更新
分类:HTML5+
4 个评论
要回复文章请先登录或注册
熊二的二
JFry
前端攻城师 (作者)
很好爱爱啊