首先请原谅我的英文。这是我的第一个问题。我已经阅读了很多关于stackoverflow常见问题和解决方案的解决方案,而IMO stackoverflow的社区是该分支中最值得信任的。iOS:“open:Permission denied”
目前我正在开发一个iOS应用程序,最近我遇到了一个问题,并经过一些研究后,我没有找到解决方案。当我使用fopen
打开现有文件,我收到以下错误:
open: Permission denied
以下是剪掉这将导致错误的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath
isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath
withIntermediateDirectories:NO
attributes:nil
error:&error];
}
NSString* filePath = [cachePath stringByAppendingPathComponent:
[NSString stringWithFormat:@"tmpmem%i.bin", count++]];
const char *cPath = [filePath cStringUsingEncoding:NSISOLatin1StringEncoding];
int file = open(cPath, O_RDWR | O_CREAT);
if (file == -1)
{
perror("open");
return NULL;
}
我期待着您的帮助。先谢谢你。
问候, B.季米特洛夫
它很难知道不知道什么是缓冲区?所有的路径应该是相对于[NSBundle mainBundle] – 2012-03-05 21:22:15
我已经更新了代码片段。 – 2012-03-05 21:37:29
在这一点上,我会不高兴,我对缓存目录并不熟悉。系统是否有可能对这里创建的东西拥有所有权?是否有某种文章或知识产权会让你相信这应该起作用? – 2012-03-05 23:29:47