Domanda

I'm probably missing something really obvious here, but:

NSError *error;
NSURL *cachesDirectory = [[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask][0];
NSLog(@"Caches directory: %@", cachesDirectory);
NSURL *tmpDirectory = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:cachesDirectory create:YES error:&error];
NSLog(@"TMP directory: %@", tmpDirectory);

// Result:
// 2013-10-28 13:37:47.972 MyApp[220:907] Caches directory: file://localhost/var/mobile/Applications/029A4948-A67A-48E5-A35F-1BBCC744E9B0/Library/Caches/
// 2013-10-28 13:37:47.976 MyApp[220:907] TMP directory: file://localhost/var/mobile/Applications/029A4948-A67A-48E5-A35F-1BBCC744E9B0/Library/(A%20Document%20Being%20Saved%20By%20MyApp%2011)/

I was expecting my temporary directory to be created inside the caches directory. From the docs:

You can also use this method to create a new temporary directory for storing things like autosave files; to do so, specify NSItemReplacementDirectory for the directory parameter, NSUserDomainMask for the domain parameter, and a valid parent directory for the url parameter. After locating (or creating) the desired directory, this method returns the URL for that directory.

Also, the definition of url:

The name of a directory inside of which you want to create a unique temporary directory for autosaving documents or some other use. This parameter is ignored unless the directory parameter contains the value NSItemReplacementDirectory and the domain parameter contains the value NSUserDomainMask. When creating a temporary directory, the shouldCreate parameter is ignored and the directory is always created.

You can see that my temporary directory is being created inside Library. What am I doing wrong?

È stato utile?

Soluzione

Looks like you are not doing anything wrong. I just tested it and found it behaving the way you described. Either the behavior does not comply with the doc or the docs are incorrect. I also happen to find the following link where people were discussing the exact same issue:

http://lists.apple.com/archives/cocoa-dev/2012/Feb/msg00197.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top