locked
NSHomeDirectory doesn't give sandboxed "Container" path even when sandboxed RRS feed

  • Question

  • User7475 posted

    According to Apple's documentation for NSHomeDirectory()...

    In OS X, it is the application’s sandbox directory or the current user’s home directory (if the application is not in a sandbox)

    However, even when I choose the option to "Enable App Sandboxing", a call to NSHomeDirectory() always returns /Users/{username} instead of /Users/{username}/Library/Containers/{bundleID}/Data. For NSHomeDirectory(), I'm currently using...

    [DllImport(MonoMac.Constants.FoundationLibrary)]
    public static extern IntPtr NSHomeDirectory();
    
    public static string ContainerDirectory
    {
        get {
            return ((NSString)Runtime.GetNSObject (NSHomeDirectory ())).ToString ();
        }
    }
    

    I've emailed Xamarin support which they "sent to the engineers", but they suggested I ask on here as well. Thoughts?

    Wednesday, November 20, 2013 7:40 PM

All replies

  • User7475 posted

    Looking at this further, I think I can verify that it is not sandboxing the app at all. Hence, NSHomeDirectory() wouldn't return a container-specific URL. Running the command line...

    codesign --display --verbose=4 --entitlements - /Applications/Calendar.app/
    

    ...then it will output nicely all the Entitlements of the stock Calendar app by Apple. However, if I run this against my signed, Release build of my app, then I get no Entitlements listed. Therefore, it looks like it's not getting sandboxed at all.

    What gives?

    Wednesday, November 20, 2013 9:32 PM
  • User16705 posted

    Are you code-signing your application? Applications must be code-signed to be eligible for sandboxing.

    Monday, November 25, 2013 12:20 AM
  • User7475 posted

    @WilliamKent, yes I am. What I've found is that if I sign it with a "Developer" cert then it does it properly, but if I do a "Release" build with a "Distribution" cert then it doesn't. However, the "App Store" build with "Distribution" cert does properly. All seems wacky to me.

    Monday, November 25, 2013 2:46 AM
  • User12054 posted

    Actually you don't want to use your App Store Distribution cert for non-AppStore builds. You want to use Developer ID.

    Monday, November 25, 2013 3:05 PM
  • User7475 posted

    @SteveFlack, that'd been good to know in one of the walkthroughs or something. :)

    Monday, November 25, 2013 3:06 PM