How do I get the users home directory in a sandboxed app?
问题 NSHomeDirectory() is retuning 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/ ? 回答1: 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