Search code examples
xcodemacossandbox

How to return the App Temp directory


I am trying to determine where to place a script file in a location where I can read/write to while being Sandboxed. While reading the Apple documentation, I seen the below:

Some path-finding APIs (above the POSIX layer) refer to app-specific locations outside of the user’s home directory. In a sandboxed app, for example, the NSTemporaryDirectory function provides a path to a directory that is outside of the user’s home directory but specific to your app and within your sandbox; you have unrestricted read/write access to it for the current user. The behavior of these path-finding APIs is suitably adjusted for App Sandbox and no code change is needed.

So basically I need to use the NSTemporaryDirectory function to return the Application Temp Directory.. but I can't seem to figure out how with the other documentation for NSTemporaryDirectory:

NSTemporaryDirectory Returns the path of the temporary directory for the current user.

NSString * NSTemporaryDirectory (void); Return Value A string containing the path of the temporary directory for the current user. If no such directory is currently available, returns nil.

Can someone please assist me in figuring out where this temp directory may be located, or how to find it with some sort of NSLog?

Please advise.


Solution

  • How about simply:

    NSString *tempDir = NSTemporaryDirectory();
    NSLog(@"tempDir='%@'", tempDir);
    

    EDIT: Updated answer to store the value in a variable, as per OP request.