【问题标题】:Accessing User Library folder in Mac App在 Mac App 中访问用户库文件夹
【发布时间】:2014-07-30 02:34:37
【问题描述】:

我正在编写一个简单的首选项窗格应用程序,它不会在 MAS 上,也不需要沙盒。

我正在尝试访问他们的用户/库目录,或者至少找到路径。

我可以这样做:

NSString *filePath = @"/Users/USERNAME/Library/";

如果我知道他们的 USERNAME,但我不知道如何获得?或者也许有更好的方法?

【问题讨论】:

标签: objective-c macos plist osx-mountain-lion


【解决方案1】:

您可以通过调用 NSUserName() 函数来获取用户名。

UPD:以错误的方式理解问题。请使用此功能

// Obtain the user's real home directory
// Normally the sandbox returns the app container's user home folder, not the real one
+ (NSString *)homeDirectory {
    struct passwd *pw = getpwuid(getuid());
    return [NSString stringWithUTF8String:pw->pw_dir];
}

【讨论】:

    猜你喜欢
    • 2014-08-01
    • 2023-03-17
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 2014-11-17
    • 1970-01-01
    相关资源
    最近更新 更多