复制代码var wgtWaiting = null;
function downloadWgt() {
wgtWaiting = plus.nativeUI.showWaiting("开始下载");
var wgtUrl = "http://192.168.51.103/release/download/wgt/v1.0.11.wgt";
var wgtOption = { filename: "_doc/update/", retry: 1 };
var task = plus.downloader.createDownload(wgtUrl, wgtOption, function (download, status) {
if (status == 200) {
wgtWaiting.setTitle("开始安装");
installWgt(download.filename);
} else {
mui.alert("应用升级失败!");
wgtWaiting.close();
}
});
task.addEventListener("statechanged", function (download, status) {
switch (download.state) {
case 2:
wgtWaiting.setTitle("已连接到服务器");
break;
case 3:
var percent = download.downloadedSize / download.totalSize * 100;
wgtWaiting.setTitle("已下载 " + parseInt(percent) + "%");
break;
case 4:
wgtWaiting.setTitle("下载完成");
break;
}
});
task.start();
};
function installWgt(wgtpath) {
plus.runtime.install(wgtpath, {}, function (wgtinfo) {
wgtWaiting.close();
mui.alert("更新完成,须重启应用!", function () {
plus.runtime.restart();
});
}, function (error) {
wgtWaiting.close();
mui.alert("应用更新失败!\n" + error.message);
});
};
Danny
- 发布:2015-11-26 16:59
- 更新:2016-09-08 17:35
- 阅读:4849
Danny (作者)
http://ask.dcloud.net.cn/question/13313
2015-12-08 08:28
panpanhtai
我的解决了,降低调用次数就好了
2015-12-08 09:45
7***@qq.com
回复 panpanhtai:调用次数修改哪个值?
2018-09-05 14:04