Search code examples
macoscocoansuserdefaultssandbox

Mac sandbox created but no NSUserDefaults plist


I'm trying to track down some issues arising from sandbox creation. Under multiple circumstances it appears that an NSUserDefaults .plist file is not created in Data/Library/Preferences. I have seen this in the debugger and when launching the app from the Applications directory. I have not tried archiving, signing the app and then launching. Is that required?

An alias file ending in .LSSharedFileList.plist is created but it points to itself and therefore does not exist.

I don't know if it's related but Console reports:

appleeventsd[72]: <rdar://problem/11489077> A sandboxed application with pid ... checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013  { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." }  (handleMessage()/appleEventsD.cp #2072) client-reqs-q

Thanks.


Solution

  • Could this be related to the caching of NSUserDefaults?

    In recent OS X versions the defaults are not immediately written to disk so you might not see them right away. You might want to try synching the prefs manually - From NSUserDefaults Class Reference:

    At runtime, you use an NSUserDefaults object to read the defaults that your application uses from a user’s defaults database. NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value. The synchronize method, which is automatically invoked at periodic intervals, keeps the in-memory cache in sync with a user’s defaults database.

    Although I believe even that might not immediately write the defaults to disk in 10.9 anymore as some daemon caching the user defaults is now also involved.

    Check also

    Reading NSUserDefaults from helper app in the sandbox

    Objective-C NSUserDefaults caching prevents another app from accurately reading changes

    When (not) to abuse NSUserDefaults