cocos版本在2.1版本前的wx-downloader.js在资源加载失败时的处理逻辑有问题,可以自己重写失败的尝试逻辑。在wx-downloader.js文件下面找到这个方法downloadRemoteFile,修改为: [代码]// 下载失败文件[代码][代码]const _downloadErrFileArr = [];[代码][代码]// 失败最大次数[代码][代码]const _downloadMaxErrNum = 3;[代码] [代码]function[代码] [代码]downloadRemoteFile(item, callback) {[代码][代码] [代码][代码]// Download from remote server[代码][代码] [代码][代码]var[代码] [代码]relatUrl = item.url;[代码] [代码] [代码][代码]// filter protocol url (E.g: https:// or http:// or ftp://)[代码][代码] [代码][代码]if[代码] [代码](REGEX.test(relatUrl)) {[代码][代码] [代码][代码]callback([代码][代码]null[代码][代码], [代码][代码]null[代码][代码]);[代码][代码] [代码][代码]return[代码][代码];[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]var[代码] [代码]remoteUrl = wxDownloader.REMOTE_SERVER_ROOT + [代码][代码]'/'[代码] [代码]+ relatUrl;[代码][代码] [代码][代码]item.url = remoteUrl;[代码][代码] [代码][代码]wx.downloadFile({[代码][代码] [代码][代码]url: remoteUrl,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]if[代码] [代码](res.statusCode === 404) {[代码][代码] [代码][代码]cc.warn([代码][代码]"Download file failed: "[代码] [代码]+ remoteUrl);[代码][代码] [代码][代码]callback({[代码][代码] [代码][代码]status: 0,[代码][代码] [代码][代码]errorMessage: res && res.errMsg ? res.errMsg : [代码][代码]"Download file failed: "[代码] [代码]+ remoteUrl[代码][代码] [代码][代码]});[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]if[代码] [代码](res.tempFilePath) {[代码][代码] [代码][代码]// http reading is not cached[代码][代码] [代码][代码]var[代码] [代码]temp = res.tempFilePath;[代码][代码] [代码][代码]var[代码] [代码]localPath = wx.env.USER_DATA_PATH + [代码][代码]'/'[代码] [代码]+ relatUrl;[代码][代码] [代码][代码]// check and mkdir remote folder has exists[代码][代码] [代码][代码]ensureDirFor(localPath, [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]// Save to local path[代码][代码] [代码][代码]wx.saveFile({[代码][代码] [代码][代码]tempFilePath: res.tempFilePath,[代码][代码] [代码][代码]filePath: localPath,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]// cc.log('save:' + localPath);[代码][代码] [代码][代码]item.url = res.savedFilePath;[代码][代码] [代码][代码]if[代码] [代码](item.type && non_text_format.indexOf(item.type) !== -1) {[代码][代码] [代码][代码]nextPipe(item, callback);[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]readText(item, callback);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]// Failed to save file, then just use temp[代码][代码] [代码][代码]console.log(res && res.errMsg ? res.errMsg : [代码][代码]'save file failed: '[代码] [代码]+ remoteUrl);[代码][代码] [代码][代码]console.log([代码][代码]'It might be due to out of storage spaces, you can clean your storage spaces manually.'[代码][代码]);[代码][代码] [代码][代码]item.url = temp;[代码][代码] [代码][代码]if[代码] [代码](item.type && non_text_format.indexOf(item.type) !== -1) {[代码][代码] [代码][代码]nextPipe(item, callback);[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]readText(item, callback);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]if[代码] [代码](_downloadErrFileArr.filter(url => url === relatUrl).length > _downloadMaxErrNum) {[代码][代码] [代码][代码]callback({[代码][代码] [代码][代码]status: 0,[代码][代码] [代码][代码]errorMessage: res && res.errMsg ? res.errMsg : [代码][代码]"Download file failed: "[代码] [代码]+ remoteUrl[代码][代码] [代码][代码]}, [代码][代码]null[代码][代码]);[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]item.url = relatUrl;[代码][代码] [代码][代码]downloadRemoteFile(item, callback);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]}[代码]
小游戏ios正常,安卓一直卡在加载100%,是怎么回事小游戏微信开发者工具正常无报错,ios预览正常,安卓预览一直卡在加载100%,但安卓真机调试时,断点后又可以进去(控制台无报错信息),有人碰到过类似的问题吗?
2019-08-16