My app is sandboxed (as per the latest App Store guidelines), and I want to create some temporary files.
Am I allowed to do so? If "yes", WHERE am I allowed to do it? Is there any prespecified path? (And a command to access that path?)
My app is sandboxed (as per the latest App Store guidelines), and I want to create some temporary files.
Am I allowed to do so? If "yes", WHERE am I allowed to do it? Is there any prespecified path? (And a command to access that path?)
You should use the NSTemporaryDirectory()
function, which will find and return the appropriate temporary folder for your application (regardless of sandbox status, OS version, and a host of other things). Take a look at this Cocoa With Love post for much more detail about NSTemporaryDirectory()
and other temporary directory-related details.
There is a good article about temporary directories on NSHipster:
http://nshipster.com/nstemporarydirectory/
The author suggests this code which is working perfectly with sandboxed apps as well:
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];