From dcc7e5d96ba6025a0d8172308a5be5587786cf73 Mon Sep 17 00:00:00 2001 From: leo <907600065@qq.com> Date: Sat, 29 Dec 2018 18:29:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=83=AD=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=EF=BC=8C=E5=8F=AF=E4=BB=A5=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E3=80=82=E7=84=B6=E5=90=8E=E6=96=B0=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HotUpdateDemo/assets/Script/HotUpdate.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/HotUpdateDemo/assets/Script/HotUpdate.js b/HotUpdateDemo/assets/Script/HotUpdate.js index 8a7b5f3..bae01d0 100644 --- a/HotUpdateDemo/assets/Script/HotUpdate.js +++ b/HotUpdateDemo/assets/Script/HotUpdate.js @@ -71,6 +71,16 @@ cc.Class({ this.checkUpdate(); }, + /** + * 错误处理和失败重试 + */ + downloadFailedAssets() { + console.log('downloadFailedAssets'); + this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.updateCb.bind(this)); + cc.eventManager.addListener(this._updateListener, 1); + this._am.downloadFailedAssets(); + }, + /** * 用于当检查热更新回调过慢时 */ @@ -98,6 +108,8 @@ cc.Class({ * 下载文件进度 */ onDownloadProgess(byteProgress, fileProgress) { + byteProgress = Math.round(byteProgress * 100) / 100 || 0; + fileProgress = Math.round(fileProgress * 100) / 100 || 0; if (this.progressFn) this.progressFn(fileProgress, byteProgress); }, @@ -107,7 +119,7 @@ cc.Class({ * @param {*} err */ onFailure(type) { - console.log('type=', type, 'err=', err); + console.log('type=', type); if (this.failedFn) this.failedFn(type); }, @@ -215,6 +227,7 @@ cc.Class({ failed = true; break; case jsb.EventAssetsManager.UPDATE_FINISHED: + console.log('UPDATE_FINISHED'); // this.panel.info.string = 'Update finished. ' + event.getMessage(); needRestart = true; break; @@ -236,10 +249,10 @@ cc.Class({ //下载失败 if (failed) { console.log('Hotupdate failure'); + this.onFailure(ErrCode.updateFailed); cc.eventManager.removeListener(this._updateListener); this._updateListener = null; this._updating = false; - this.onFailure(ErrCode.updateFailed); } if (needRestart) {