NSHomeDirectory()
is returning my sandbox root, not my home directory. [@"~" stringByExpandingTildeInPath]
is doing the same thing.
This /Users/username/Library/Containers/appID/Data
is what's being returned. How do I get /Users/username/
?
If you want the path to the user's real home directory you can use:
char *realHome = getpwuid(getuid())->pw_dir;
Full example:
#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];
}
This gives you the path to the user's home, but does not automatically give you access to that folder. As noted in comments, you can use this path for:
NSHomeDirectory()