沙盒Mac应用程序可以在哪里保存文件? [英] Where can a sandboxed Mac app save files?

查看:343
本文介绍了沙盒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.

这篇关于沙盒Mac应用程序可以在哪里保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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