from :https://blog.csdn.net/u013654125/article/details/78320365
日前,有网友看了我的博客后,发消息告诉我遇到一个错误:说是找不到system。当前我的项目是没有问题的,没能找出问题所在。
报错如下:Call to unavailable function 'system': not available on iOS。写这句话是为了写关键字,让大家容易搜索。
后来,还是网友自己解决的,并把解决方案发给了我。
再后来,我也更新了Xcode,更新到Xcode9,也遇到问题,想起网友发给我的解决方案,一用,程序立马跑得飞起。
这里,我就借用一下网友的答案说给大家说一下这个情况。
在更新了Xcode9后,api也跟着更新了,所以有api接口错误很正常,按照接下来的操作就可以解决了。
![](https://img.haomeiwen.com/i4313441/0ffe49ff8ca111ea.png)
原因:Xcode9将system api删除,使用ntfw api替代,解决方法如下:
一、在#include <dirent.h>下方添加:
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID)
#include <ftw.h>
#endif
![](https://img.haomeiwen.com/i4313441/fcc199ee10b06532.png)
二、在removeDirectory方法上添加
// removeDirectory
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
}
// removeDirectory :
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://img.haomeiwen.com/i4313441/bba04d7207cfbd85.png)
网友评论