Downloader

  • include “network/CCDownloader.h”
  • メンバ変数に以下を追加
    • std::unique_ptr m_downloader;
  • メンバ変数初期化
    • m_downloader.reset(new network::Downloader());
  • 各種ハンドラ設定

// define progress callback

m_downloader->onTaskProgress = [this](const network::DownloadTask& task,
int64_t bytesReceived,
int64_t totalBytesReceived,
int64_t totalBytesExpected)
{
log(“”);
};

// define success callback
m_downloader->onDataTaskSuccess = [this](const cocos2d::network::DownloadTask& task,
std::vector& data)
{
log(“”);
};
m_downloader->onFileTaskSuccess = [this](const cocos2d::network::DownloadTask& task)
{
log(“”);
this->doOutput(“download succeded\n”);
};
// define failed callback
m_downloader->onTaskError = [this](const cocos2d::network::DownloadTask& task,
int errorCode,
int errorCodeInternal,
const std::string& errorStr)
{
log(“”);
this->doOutput(“download failed\n”);
};

  • ダウンロード処理開始
string dst = FileUtils::getInstance()->getWritablePath() + g.m_projectName + ".prj/images/" + fileName;
m_downloader->createDownloadFileTask(url, dst, fileName);