源代码:
bool AssetsManager::checkUpdate()
{
if (_versionFileUrl.size() == 0) return false;
_curl = curl_easy_init();
if (! _curl)
{
CCLOG("can not init curl");
return false;
}
// Clear _version before assign new value.
_version.clear();
CURLcode res;
curl_easy_setopt(_curl, CURLOPT_URL, _versionFileUrl.c_str());
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, getVersionCode);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &_version);
if (_connectionTimeout) curl_easy_setopt(_curl, CURLOPT_CONNECTTIMEOUT, _connectionTimeout);
res = curl_easy_perform(_curl);
if (res != 0)
{
sendErrorMessage(kNetwork);
CCLOG("can not get version file content, error code is %d", res);
curl_easy_cleanup(_curl);
return false;
}
string recordedVersion = CCUserDefault::sharedUserDefault()->getStringForKey(KEY_OF_VERSION);
if (recordedVersion == _version)
{
sendErrorMessage(kNoNewVersion);
CCLOG("there is not new version");
// Set resource search path.
setSearchPath();
return false;
}
CCLOG("there is a new version: %s", _version.c_str());
return true;
}
为什么执行成功(res ==0 )后 没有调用 回调 getVersionCode 函数
请求的URL是项目中的URL:
pAssetsManager = new AssetsManager(“http://raw.github.com/minggo/AssetsManagerTest/master/package.zip”,
“http://raw.github.com/minggo/AssetsManagerTest/master/version”,
以上URL在浏览器中都可以正常打开看到东西的,和下面的内部URL打开效果一致
如果换成内部URL就没有问题可以正常回调:
pAssetsManager = new AssetsManager(“http://192.168.1.10/package.zip”,
“http://192.168.1.10/version.txt”,