1. 程式人生 > >解決Call to unavailable function 'system': not available on iOS

解決Call to unavailable function 'system': not available on iOS

官方論壇的連結地址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)
}
儲存,編譯,成功~