我正在尝试编写逻辑测试来调试将图像数据保存到磁盘的方法。我使用以下几行将图像数据写入文档目录:
docspath = [[NSString alloc] initWithString:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, TRUE) objectAtIndex:0]];
fullpath = [[NSString alloc] initWithFormat:@"%@/%@", docspath, _name];
BOOL written = [fileData writeToFile:fullpath options:NSDataWritingAtomic error:&dataerror];
除了没有写入数据并且错误描述没有返回这样的文件或目录。我在 iOS 5.1 模拟器的测试目标下运行此代码。我是否需要创建中间目录才能访问文档目录,或者在测试目标下写入磁盘是否存在其他问题?
返回的错误:
2012-06-29 16:13:31.819 otest[4597:7b03] /Users/myaccount/xcode_projects/myproject/myproject/myfolder/MMFileManager.m - 285: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x1e1e3a0 {NSUserStringVariant=Folder, NSFilePath=/Users/myaccount/Library/Application Support/iPhone Simulator/5.1/Documents/mmLogo.png, NSUnderlyingError=0x1e1b430 "The operation couldn’t be completed. No such file or directory"}