How do I get the users home directory in a sandboxed app?

前端 未结 3 1824
[愿得一人]
[愿得一人] 2020-12-09 02:49

NSHomeDirectory() is retuning my sandbox root, not my home directory. [@\"~\" stringByExpandingTildeInPath] is doing the same thing.

This <

3条回答
  •  不知归路
    2020-12-09 03:43

    From apple documentation:

    Accessing User Data

    Mac OS X path-finding APIs, above the POSIX layer, return paths relative to the container instead of relative to the user’s home directory. If your app, before you sandbox it, accesses locations in the user’s actual home directory (~) and you are using Cocoa or Core Foundation APIs, then, after you enable sandboxing, your path-finding code automatically uses your app’s container instead.

    For first launch of your sandboxed app, Mac OS X automatically migrates your app’s main preferences file. If your app uses additional support files, perform a one-time migration of those files to the container, as described in “Migrating an App to a Sandbox.”

    If you are using a POSIX command such as getpwuid to obtain the path to the user’s actual home directory, consider instead using a Cocoa or Core Foundation symbol such as the NSHomeDirectory function. By using Cocoa or Core Foundation, you support the App Sandbox restriction against directly accessing the user’s home directory.

    If your app requires access to the user’s home directory in order to function, let Apple know about your needs using the Apple bug reporting system.

提交回复
热议问题