版本1.9.3
Simulator: E/jswrapper (267): ERROR: Uncaught TypeError: this._am.setEventCallback is not a function, location: assets/Script/ui/LoadScene/Update_UI.js:0:0
this._am.setEventCallback(this.checkCb.bind(this)); 照着官网的例子写的
我的报错是这个:
08-15 18:20:28.980 9482-9530/org.cocos2d.tutorialhotupdate E/jswrapper: ERROR: Uncaught TypeError: Cannot read property ‘nativeUrl’ of null, location: src/project.dev.js:0:0
properties: {
panel: UpdatePanel,
manifestUrl: {
type: cc.Asset,
default: null
},
updateUI: cc.Node,
_updating: false,
_canRetry: false,
_storagePath: ‘’
},
manifestUrl 这里怎么实现知道吗? 请问里面应该拖什么组件进去 知道吗?
你这个问题我解决了,首先把cc.Asset改为cc.RawAsset,然后绑定你的manifest文件, var url = this.manifestUrl;获取路径,后边不用加nativeUrl
我的已经成功跑起来了
一绑定manifest 就提示类型错误了
这样声明就对了,官网例子那种我这也一直出错,
谢谢 我好像也走到你发帖中的错误了
我看了一下老文档,然后这样写的
this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this));
cc.eventManager.addListener(this._updateListener, 1);
老哥 解决了吗?
解决了,就上边我写的代码
能热更新了?
可以了,自己搭建了一个临时的本地服务器,测试没有啥问题了,已经进行下边的功能开发了
/**
* 更新资源
*/
UpdateResource:function(){
this.load_title.string=“正在进行更新检测…”;
if(!cc.sys.isNative){
console.log("Hot update is only available in Native build ,now is not ");
return;
}
this._storagePath=((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ‘/’) + ‘update’); //获取本地缓存目录
this._am = new jsb.AssetsManager(’’, this._storagePath);
this._am.setVerifyCallback(function (path, asset) {
var compressed = asset.compressed;
var expectedMD5 = asset.md5;
var relativePath = asset.path;
var size = asset.size;
if (compressed) {
console.log("Verification passed : " + relativePath);
return true;
}
else {
console.log("Verification passed : " + relativePath + ’ (’ + expectedMD5 + ‘)’);
return true;
}
});
if (cc.sys.os === cc.sys.OS_ANDROID) {
this._am.setMaxConcurrentTask(2);
}
this.checkUpdate();
},
//检查更新
checkUpdate: function () {
if (this._updating) {
console.log(‘Checking or updating …’);
return;
}
if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
var url = this.manifestUrl;
if (cc.loader.md5Pipe) {
url = cc.loader.md5Pipe.transformURL(url);
}
console.log(this.manifestUrl);
this._am.loadLocalManifest(url);
} if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) { console.log('Failed to load local manifest ...'); sendEvent("LoadCacheResource"); return; } //this._am.setEventCallback(this.checkCb.bind(this)); this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this)); cc.eventManager.addListener(this._updateListener, 1); this._am.checkUpdate(); this._updating = true; }, checkCb:function(event){ //cc.log('Code: ' + event.getEventCode()); switch (event.getEventCode()) { case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: console.log("Fail to download manifest file, hot update skipped."); this._need_update=false; //sendEvent("LoadCacheResource"); this.load_title.string="更新异常..."; //this.updateFinish(0,event.getEventCode()); // this.show_errMsg(); break; case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: console.log("Already up to date with the latest remote version."); this._need_update=false; //sendEvent("LoadCacheResource"); this.updateFinish(1); break; case jsb.EventAssetsManager.NEW_VERSION_FOUND: console.log("New version found, please try to update."); this.load_title.string="发现新版本,即将准备更新,请勿关闭..."; this._need_update=true; break; default: return; } // this._am.setEventCallback(null); this._updateListener = new jsb.EventListenerAssetsManager(this._am,null); cc.eventManager.addListener(this._updateListener, 1); this._checkListener = null; this._updating = false;
//检查完毕,如果需要更新,调用热跟新方法 if(this._need_update){ this.hotUpdate(); } }, //立即更新 hotUpdate: function () { if (this._am && !this._updating) { //this._am.setEventCallback(this.updateCb.bind(this)); this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.updateCb.bind(this)); cc.eventManager.addListener(this._updateListener, 1); if (this._am.getState() === jsb.AssetsManager.State.UNINITED) { var url = this.manifestUrl; if (cc.loader.md5Pipe) { url = cc.loader.md5Pipe.transformURL(url); } this._am.loadLocalManifest(url); }
this._failCount = 0; this._am.update(); //this.panel.updateBtn.active = false; this._updating = true; } }, updateCb: function (event) { switch (event.getEventCode()) { case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: case jsb.EventAssetsManager.UPDATE_FAILED: case jsb.EventAssetsManager.ERROR_UPDATING: case jsb.EventAssetsManager.ERROR_DECOMPRESS: console.log('No local manifest file found, hot update skipped.'); this.updateFinish(0,event.getEventCode()); this._updateListener = null; cc.eventManager.addListener(this._updateListener, 1); this._updating = false; break; case jsb.EventAssetsManager.UPDATE_PROGRESSION: //更新进度 cc.log(event.getPercent()+" :更新进度"); this.load_Progress_Bar.getComponent(cc.ProgressBar).progress=event.getPercent(); console.log(parseInt(event.getPercent())+"-----------"+event.getPercent()); this.load_title.string="正在更新...("+ parseInt(event.getPercent()) + '% : '+")"; var msg = event.getMessage(); break; case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: //已经更新到最新的远程版本了 console.log('Already up to date with the latest remote version.'); this._updateListener = null; cc.eventManager.addListener(this._updateListener, 1); this._updating = false; this.updateFinish(1); break; case jsb.EventAssetsManager.UPDATE_FINISHED: //更新完成 console.log('Update finished. ' + event.getMessage()); this.updateFinish(2); break; default: break; } },
这是我的代码,希望对你有帮助,
UpdateResource 是入口函数, 还有就是manifest文件生成也要注意不能出错
感谢 您提供的代码 测试可以使用 万分感谢 只是 是否复制少了一段代码呢? 我这边报 this.updateFinish is not a function, 错误 缺少这个函数 updateFinish
updateFinish这个是我自己写的一个函数,主要是更新完成后的一些逻辑,我没拷
ok 我改成自己的了 已经完美运行 感谢
请问原来热更新需要versionCompareHandle的那一段
现在是不是不需要了?
同样遇到了,希望官方能稍微维护一下热更新的东西;
还有同学你的老文档在哪找的;