为沙盒 Cocoa 应用程序创建临时文件
我的应用是沙盒(根据最新的 App Store 指南),我想创建一些临时文件.
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?)
您应该使用 NSTemporaryDirectory()
函数,该函数将为您的应用程序查找并返回适当的临时文件夹(无论沙箱状态如何)、操作系统版本以及许多其他内容).查看这篇 Cocoa With Love 帖子,了解更多关于NSTemporaryDirectory()
和其他与临时目录相关的详细信息.
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.