如何返回 App Temp 目录 [英] How to return the App Temp directory

查看:87
本文介绍了如何返回 App Temp 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定将脚本文件放在沙盒中可以读写的位置.在阅读Apple文档时,我看到了以下内容:

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:

某些路径查找API(位于POSIX层之上)是指用户主目录之外的特定于应用的位置.例如,在沙盒应用程序中,NSTemporaryDirectory函数提供了一个目录路径,该目录位于用户的主目录之外,但特定于您的应用程序和沙箱内;您对当前用户具有不受限制的读/写访问权限.这些路径查找API的行为已针对App Sandbox进行了适当调整,无需更改代码.

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.

所以基本上我需要使用NSTemporaryDirectory函数来返回应用程序临时目录..但是我似乎无法弄清楚如何使用NSTemporaryDirectory的其他文档:

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返回当前用户的临时目录的路径.

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

NSString * NSTemporaryDirectory(void);返回值一个字符串,其中包含当前用户的临时目录的路径.如果当前没有这样的目录,则返回nil.

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.

有人可以协助我确定此临时目录的位置,或者如何通过某种NSLog找到它吗?

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?

请告知.

推荐答案

简单地说:

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

编辑:根据OP请求,更新了答案以将值存储在变量中.

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

这篇关于如何返回 App Temp 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆