Hi everyone, I need help with native.Downloader. I want to create some download task, in older version (before cocos creator 3.6) I use jsb.Downloader and its work properly. But, in cocos creator 3.6 jsb is deprecated and need to use native namespace, when I use native.Downloader in the same way, downloadTask is created but the callback (success, progress, and error) not called. When I try to log downloader callback the output is ‘undefined’. This is my code :
import { log, native, _decorator } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('MyDownloader')
export class MyDownloader {
private static _instance: MyDownloader;
protected constructor() { }
public static get instance(): MyDownloader {
MyDownloader._instance ??= new MyDownloader();
return MyDownloader._instance;
}
public startDownload(bundleUrl: string) {
const path = native.fileUtils.getWritablePath();
log(`writable path: ${path}`);
const downloader = new native.Downloader();
downloader.onSuccess = (task) => {
log('on success');
}
downloader.onProgress = (task, bytesReceived, totalBytesReceived, totalBytesExpected) => {
log('on progress');
}
downloader.onError = (task, errorCode, errorCodeInternal, errorStr) => {
log('on error');
}
const task = downloader.createDownloadTask(bundleUrl, path);
log(JSON.stringify(task));
log(JSON.stringify(downloader.onSuccess)) // undefined;
log(JSON.stringify(downloader.onProgress)) // undefined;
log(JSON.stringify(downloader.onError)) // undefined;
}
}
There is something wrong with my code?