官方论坛的链接地址Call to unavailable function ‘system’: not available on iOS官方已经帮忙给出了解决办法,这里,将官方的办法重新讲解一遍。
cocos/platform/CCFileUtils.cpp
在#include <dirent.h>下面添加
// android doesn't have ftw.h
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#include <ftw.h>
#endif
找到 第一个 bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
方法 在后面添加
namespace
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
int rv = remove(fpath);
if (rv)
perror(fpath);
return rv;
}
#endif
}
找到 bool FileUtils::removeDirectory(const std::string& path)方法 修改为
bool FileUtils::removeDirectory(const std::string& path)
{
#if !defined(CC_TARGET_OS_TVOS)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
if (nftw(path.c_str(), unlink_cb, 64, FTW_DEPTH | FTW_PHYS) == -1)
return false;
else
return true;
#else
std::string command = "rm -r ";
// Path may include space.
command += "\"" + path + "\"";
if (system(command.c_str()) >= 0)
return true;
else
return false;
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#endif // !defined(CC_TARGET_OS_TVOS)
}
保存,编译,成功~