获取用户路径OS X中的库文件夹 [英] Getting path to users Library folder in OS X

查看:261
本文介绍了获取用户路径OS X中的库文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开一个NSSavePanel与用户库文件夹作为目标文件夹。通常我通过在 [NSSavePanel beginSheetForDirectory] ​​中输入〜/ Library / 来实现。

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].

这个工作正常,只要应用程序没有沙箱。对于沙盒应用程序,这将导致 NSSavePanel 尝试访问应用程序文档框中的文件夹。

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".

我不能引用 / Users / username / Library / ,因为我不知道用户 username 在运行时。

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?

推荐答案

不知道这是否会在沙盒应用程序上工作,我现在做。这将返回/ User / TheirUserName

Not sure if this will work on a sandboxed application but this is how I do it right now. This will return /User/TheirUserName

-(NSString *)homeDirectory
{
    return NSHomeDirectory();
}

这篇关于获取用户路径OS X中的库文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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