我正在将一个C lib移植到iOS,并遇到代码调用tmpnam的问题.该函数返回“var / tmp / tmp.0.0xGlzv”,我假设它在我的应用程序允许播放的“沙箱”之外.次序fopen返回“Operation not allowed”.有可行的替代品吗?
解决方法:
关于什么
[NSTemporaryDirectory() stringByAppendingPathComponent:@"myTempFile1.tmp"];
?
对于唯一的文件名,请尝试以下方法:
NSString *uniqueTempFile()
{
int i = 1;
while (YES)
{
NSString *currentPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%i.tmp", i]];
if (![[NSFileManager defaultManager] fileExistsAtPath:currentPath])
return currentPath;
else
{
i++;
}
}
}
这很简单,但可能不是最有记忆效应的答案.
原文地址:https://codeday.me/bug/20190827/1736698.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。