我有以下代码,我从Xcode中的Swift主程序调用,例如,在虚拟iPhone中的模拟器中运行它时,它可以工作。它创建/tmp/MYFIFO。
int32_t init_udpC(void) {
static char *filename="/tmp/MYFIFO";
umask(0);
unlink(filename);
if((mkfifo(filename, 0666)) == -1){
perror("mkfifo");
exit(2);
}
if((fd=open("/tmp/MYFIFO",O_RDWR|O_APPEND)) == -1) {
perror("open");
exit(2);
}
return fd;
}在代码失败的物理设备上运行它
mkfifo: Operation not permitted
发布于 2018-12-27 03:27:07
这是因为iOS沙箱。在iOS上,你的应用程序不允许访问/tmp/。它在模拟器中工作,因为您在macOS上运行,在那里它是正常的。
你需要使用一个允许你的应用程序访问的路径。一种可能是将路径替换为
const char *filename=[[NSTemporaryDirectory() stringByAppendingPathComponent:@"MYFIFO"] UTF8String];还有其他有效的路径--关键是您必须被允许访问该目录。
https://stackoverflow.com/questions/53934274
复制相似问题