Create a temporary file for Cocoa sandboxed application

My application is isolated (according to the latest recommendations on the App Store), and I want to create several temporary files.

Can I do it? If yes, WHERE do I allow this to be done? Is there any predefined path? (And the command to access this path?)

+8
objective-c cocoa app-store sandbox temporary-files
source share
2 answers

You should use the NSTemporaryDirectory() function, which will find and return the appropriate temporary folder for your application (regardless of the state of the sandbox, OS version, and many other things). Take a look at this Cocoa with love for more details on NSTemporaryDirectory() and other temporary reference data.

+12
source share

NSHipster has a good article on temporary directories:

http://nshipster.com/nstemporarydirectory/

The author offers this code that works great with isolated applications:

 NSError *error; NSString *globallyUniqueString = [[NSProcessInfo processInfo] globallyUniqueString]; NSString *tempDirectoryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:globallyUniqueString]; NSURL *tempDirectoryURL = [NSURL fileURLWithPath:tempDirectoryPath isDirectory:YES]; [[NSFileManager defaultManager] createDirectoryAtURL:tempDirectoryURL withIntermediateDirectories:YES attributes:nil error:&error]; 
+5
source share

All Articles