cocoscreator安卓怎么下载服务器json文件

cocoscreator安卓怎么下载服务器json文件

download(url, storagePath, successCb, progressCb, errorCb){
		if (window.jsb) {
			let downloader = new jsb.Downloader(), timer, index = DOWNLOAD_POOL.length;
			DOWNLOAD_POOL.push(downloader)
			downloader.setOnTaskProgress((task, bytesReceived, totalBytesReceived, totalBytesExpected)=>{
				if (downloader.willDie) {
					return
				}
				// console.log('[jsdebug]-FileUtil.download progress ', url, totalBytesReceived / totalBytesExpected)
				if(progressCb) progressCb(url, bytesReceived, totalBytesReceived, totalBytesExpected);
			});
			downloader.setOnFileTaskSuccess(()=>{
				if (downloader.willDie) {
					return
				}
				// console.log('[jsdebug]-FileUtil.download success ', url, storagePath)
				clearInterval(timer)
				if(successCb) successCb(url, storagePath);
				DOWNLOAD_POOL[index] = null
			});
			downloader.setOnTaskError((task, errorCode, errorCodeInternal, errorStr)=>{
				if (downloader.willDie) {
					return
				}
				clearInterval(timer)
				// console.log('[jsdebug]-FileUtil.download failed ', url, errorCode, errorCodeInternal, errorStr)
				if(errorCb) errorCb(url, errorCode, errorCodeInternal, errorStr);
				DOWNLOAD_POOL[index] = null
			});
			downloader.createDownloadFileTask(url, storagePath);
			console.log('[jsdebug]-FileUtil.download',url, storagePath);
			// timer = setInterval(()=>{
			// 	console.log("call set progress cb", _bytesReceived/_totalBytesReceived)
			// 	if(progressCb) progressCb(_url, _bytesReceived, _totalBytesReceived, _totalBytesExpected);
			// }, 1000)
		} else {
			if(errorCb) errorCb(url, -1, -1, "!jsb");
		}
    },

好的,谢谢,我先看一下~