获取 OS X 中用户库文件夹的路径
我需要打开一个 NSSavePanel,并将用户库文件夹作为目标文件夹。通常,我会通过在 [NSSavePanel beginSheetForDirectory]
中输入 ~/Library/
来完成此操作。
只要应用程序没有被沙箱化,这种方法就可以正常工作。对于沙盒应用程序,这将导致 NSSavePanel
尝试访问应用程序文档“盒子”内的文件夹。
我无法引用 /Users/username/Library/
因为我在运行时不知道用户username
。那么我如何链接到可可中的这条路径呢?
I need to open a NSSavePanel with the users Library folder as destination folder. Normally I would do this by entering ~/Library/
in [NSSavePanel beginSheetForDirectory]
.
This works fine as long as the application is not sandboxed. For sandboxed applications this will result in the NSSavePanel
trying to access a folder inside the applications document "box".
I cannot refer to /Users/username/Library/
as I do not know the users username
at runtime. So how do I link to this path in cocoa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定沙箱如何适应这一点,但您可以使用以下命令找到用户的库目录:
I'm not sure how sandboxing fits in with this, but you can find the user's library directory using:
不确定这是否适用于沙盒应用程序,但这就是我现在的做法。这将返回 /User/他们的用户名
Not sure if this will work on a sandboxed application but this is how I do it right now. This will return /User/TheirUserName
这取决于您想要实现的目标。
~/Library/
文件夹中的数据,可以定义一个 迁移策略将数据移回沙箱。It depends what you are trying to achieve.
~/Library/
folder, you can define a migration strategy to move back the data into the sandbox.