0

Before I start, I need to stress the fact that I have looked at every post dealing with the documents directory.

So I will try to disect my problem to better help you help me.

I am developing an iOS application targeted for 5.1. I am using XCode 4.4.1 and the iOS simulator Version 5.1 (272.21).

It is in my understanding that when an app is installed in the simulator, its directory structure is mapped under

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]

This is properly reflected when I run my application.

Furthermore I am able to successfully create and use a temporary directory using the following code

NSString *tmpDir = NSTemporaryDirectory();

which results in the following path

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/tmp

The problem starts appearing when I want to work with the Documents directory that is supposed to be in

/Library/Application Support/iPhone Simulator/[IOS_VERSION]/Applications/[APP_UUID]/Documents

The following code checks for the existence of that path, and then logs it using NSLog, and even though it says it exists navigating to that location returns a file not found.

+ (NSString *) currentPath{

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];

searchPaths=nil;

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:documentPath];

if (fileExists == TRUE) {
    NSLog(@" %@ already exists",documentPath);
} else {

    NSLog(@"doesn't exists");
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;

    if(![fileManager createDirectoryAtPath:documentPath withIntermediateDirectories:true attributes:nil error:&error])
    {
        NSLog(@"Couldn't create documents directory %@",error);

    }



}

return documentPath;

}

The result is of the NSLog line is:

2012-08-09 23:12:09.813 AMM[22656:c07]  /Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B/Documents already exists

In the terminal

 > pwd
 /Users/fotis/Library/Application Support/iPhone Simulator/5.1/Applications/7CE8645A-BDD7-4AB6-8CAB-B0EF1579CD2B
 >ls -lsa
  total 0
  0 drwxr-xr-x  5 fotis  170 Aug  9 23:12 .
  0 drwxr-xr-x  3 fotis  102 Aug  9 22:50 ..
  0 drwxr-xr-x 30 fotis 1020 Aug  9 23:12 AMM.app
  0 drwxr-xr-x  4 fotis  136 Aug  9 22:50 Library
  0 drwxr-xr-x  4 fotis  136 Aug  9 22:51 tmp

As you can see, my Documents ghost directory is not there. For the life of me I cannot understand the magic behind it all. One thing to note is that I am running this in the "-didFinishLaunchingWithOptions" method of my app delegate, because I am doing some initialization there.

Any ideas?

Fotis Paraskevopoulos
  • 1,001
  • 2
  • 12
  • 19

2 Answers2

0

The Simulator is a bit clunky on that venue, it used to be that you couldn't even find the simulated sandbox while your app wasn't running on the simulator. Anyway, you should not worry about creating the Documents folder, it will always be there on the device (and also the Simulator, given that you haven't tried to delete it in-app or in Finder)

Rafael Nobre
  • 5,062
  • 40
  • 40
0

It turns out that part of my initialization process is to remove some files from the Documents directory.

So for anyone wondering about missing paths make sure that your slashes "/" are correct and your globs (*) DO NOT include your root (Documents/) folder.

What is strange however what the fact that my 'bad' code was able to remove this (for what is worth, application dependant) directory from its path.

miken32
  • 42,008
  • 16
  • 111
  • 154
Fotis Paraskevopoulos
  • 1,001
  • 2
  • 12
  • 19