沙盒Mac应用程序可以在哪里保存文件?
我的Mac应用已沙箱化,我需要保存一个文件.我在哪里保存该文件?如果没有使用打开的面板,我似乎找不到允许的特定位置.这是我在iOS上执行的操作:
My Mac app is sandboxed and I need to save a file. Where do I save this file? I can't seem to find the specific place where this is allowed without using an open panel. This is how I do it on iOS:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
在Mac上,沙盒目录的等效项是什么?
What is the equivalent for the sandboxed directory on Mac?
无论您的应用程序是否被沙箱化,该代码段都可以在Mac上运行.
That code snippet works on the Mac regardless of whether your application is sandboxed.
在非沙盒Mac应用程序中,path
将引用您家中的Documents文件夹: /Users/username/Documents
.
In a non-sandboxed Mac app, path
will refer to the Documents folder in your home: e.g. /Users/username/Documents
.
在沙盒应用中,它指的是应用沙盒中的文件夹:例如/Users/username/Library/Containers/com.yourcompany.YourApp/Documents
In a sandboxed app, it refers to a folder within the app sandbox: e.g. /Users/username/Library/Containers/com.yourcompany.YourApp/Documents
See the docs for details.