'system' is unavailable: not available on iOS

cocoa2d導出xcode工程用xcode11及以上版本編譯報錯:'system' is unavailable: not available on iOS,這是因為iOS11+廢棄了system,解決方案如下:
一、修改文件CCFileUtils.cpp
1.1在#include <dirent.h>下新增如下代碼(在1231行左右)

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#include <ftw.h>
#endif

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
}

1.2 在bool FileUtils::removeDirectory(const std::string& path)方法下實現(xiàn)改成下面的方式

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
#endif // !defined(CC_TARGET_OS_TVOS)
}

二、修改文件cocos2d_lua/external/lua/Ioslib.c
2.1在#include "lualib.h"行下新增代碼

    #include <ftw.h> 
   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; 
    } 

2.2替換方法: lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));

lua_pushinteger(L, nftw(luaL_optstring(L, 1, NULL), unlink_cb, 64, FTW_DEPTH | FTW_PHYS));

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容