我正在与其他人开发iPhone应用程序。该应用程序适用于我,但他遇到了一个bug。我们认为这个bug与他为同一个应用程序获取多个Application目录有关。在我的〜/ Library/Application Support/iPhone Simulator/User/Applications中,我一直只有一个文件夹。适用于iPhone模拟器的多个应用程序支持目录?
他说当他只在这个应用上工作时,他会得到3或4个目录。我们认为这是我们的问题,因为我们的错误与显示存储在应用程序的“文档”文件夹中的图像有关。有谁知道他为什么要结束多个目录或如何阻止它?
编辑:
这里是图像写入文件的代码:
NSData *image = [NSData dataWithContentsOfURL:[NSURL URLWithString:[currentArticle articleImage]]];
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *imagePath = [array objectAtIndex:0];
NSFileManager *NSFM = [NSFileManager defaultManager];
BOOL isDir = YES;
if(![NSFM fileExistsAtPath:imagePath isDirectory:&isDir])
if(![NSFM createDirectoryAtPath:imagePath attributes:nil])
NSLog(@"error");
imagePath = [imagePath stringByAppendingFormat:@"/images"];
if(![NSFM fileExistsAtPath:imagePath isDirectory:&isDir])
if(![NSFM createDirectoryAtPath:imagePath attributes:nil])
NSLog(@"error");
imagePath = [imagePath stringByAppendingFormat:@"/%@.jpg", [currentArticle uniqueID]];
[image writeToFile:imagePath atomically:NO];
这里是获取路径的代码时,我需要的图像:
- (NSString *)imagePath
{
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *imagePath = [array objectAtIndex:0];
return [imagePath stringByAppendingFormat:@"/images/%@.jpg", [self uniqueID]];
}
该应用程序对我很好,但我的合作伙伴说图像不会间歇性显示,并且他注意到他在他的Appl中获取了多个目录文件夹。
嗯..我们已经在使用这段代码了。也许我们的问题在于别处。 – 2010-03-30 21:53:47
也许吧。也许如果你发布了一些代码,我们可能会发现问题。 – 2010-03-30 22:07:58
我添加了代码 - 注意它有什么不对吗? – 2010-03-30 22:59:02