Multiple Application Support Directories for iPhone Simulator?

Posted by Alex G on Stack Overflow See other posts from Stack Overflow or by Alex G
Published on 2010-03-30T20:26:46Z Indexed on 2010/03/30 23:03 UTC
Read the original article Hit count: 393

Filed under:
|
|

I am developing an iPhone app with someone else. The app works fine for me, but he is running into a bug. We think this bug is related to the fact that he is getting multiple Application directories for this same app. In my ~/Library/Application Support/iPhone Simulator/User/Applications, I only have one folder at all times.

He says that he will get 3 or 4 directories when he is only working on this one app. We think this is our problem because our bug has to do with displaying images that are stored in the app's Documents folder. Does anyone know why he is ending up with multiple directories or how to stop it?

Edit:

Here is the code for writing the image to a file:

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];

And here is the code for getting the path when I need the image:

- (NSString *)imagePath
{
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *imagePath = [array objectAtIndex:0];
    return [imagePath stringByAppendingFormat:@"/images/%@.jpg", [self uniqueID]];
}

The app works great for me, but my partner says that the images don't show up intermittently, and he notices that he gets multiple directories in his Applications folder.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode