Mac开发获取home目录

获取home目录

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <assert.h>

NSString *RealHomeDirectory() {
struct passwd *pw = getpwuid(getuid());
assert(pw);
return [NSString stringWithUTF8String:pw->pw_dir];
}


NSString *home=[[[NSProcessInfo processInfo] environment] objectForKey:@"HOME"];

https://stackoverflow.com/questions/9553390/how-do-i-get-the-users-home-directory-in-objectivec-in-a-sandboxed-app

https://stackoverflow.com/questions/3020187/getting-home-directory-in-mac-os-x-using-c-language

文章作者: kyren
文章链接: http://huluo666.github.io/2018/02/08/Mac开发获取home目录/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Kyren's Blog