xcode9 cocos call to unavailable function system not available on ios
阿新 • • 發佈:2019-02-01
剛剛升級鳥xcode9,發現跑cocos專案編譯CCFileUtils.cpp異常 『call to unavailable function system not available on ios 』
解決方案:
// default implements for unix like os #include <sys/types.h> #include <errno.h> #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 { struct stat st; if (stat(dirPath.c_str(), &st) == 0) { return S_ISDIR(st.st_mode); } return false; } bool FileUtils::createDirectory(const std::string& path) { CCASSERT(!path.empty(), "Invalid path"); if (isDirectoryExist(path)) return true; // Split the path size_t start = 0; size_t found = path.find_first_of("/\\", start); std::string subpath; std::vector<std::string> dirs; if (found != std::string::npos) { while (true) { subpath = path.substr(start, found - start + 1); if (!subpath.empty()) dirs.push_back(subpath); start = found+1; found = path.find_first_of("/\\", start); if (found == std::string::npos) { if (start < path.length()) { dirs.push_back(path.substr(start)); } break; } } } DIR *dir = NULL; // Create path recursively subpath = ""; for (int i = 0; i < dirs.size(); ++i) { subpath += dirs[i]; dir = opendir(subpath.c_str()); if (!dir) { // directory doesn't exist, should create a new one int ret = mkdir(subpath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); if (ret != 0 && (errno != EEXIST)) { // current directory can not be created, sub directories can not be created too // should return return false; } } else { // directory exists, should close opened dir closedir(dir); } } return true; } 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) { #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) #else return false; #endif // !defined(CC_TARGET_OS_TVOS) }
參考:https://github.com/cocos-creator/cocos2d-x-lite/pull/828/commits/adc421c27a74317115af9763ec205d44b4dd52bc