Accessing Sandboxed Application Preference File

If my application's bundle identifier is net.jim.HelloApp, then the path to its sandbox library folder is


/Users/me/Library/Containers/net.jim.HelloApp/Data/Library


, where me is the current user. I can get that path with


FileManager.SearchPathDirectory.libraryDirectory


I wonder if there is a quick way of getting the path to its plist file in the preference folder? Its path should be


/Users/me/Library/Containers/net.jim.HelloApp/Data/Library/Preferences/net.jim.HelloApp.plist


It seems that the application will try to access this file when the user resizes application window. The thing is that my application doesn't even have the restorable switch on. If this file doesn't exist, then the application can crash.

The correct way to access preferences like this is via the

NSUserDefaults
API (or
CFPreferences
if you’re feeling particularly masochistic :-). Trying to work with preferences files directly is unreliable because the files are managed by a system process (
cfprefsd
) that holds a lot of internal state.

It seems that the application will try to access this file when the user resizes application window. The thing is that my application doesn't even have the restorable switch on. If this file doesn't exist, then the application can crash.

I’m not sure what’s going on here but I recommend that you investigate this issue directly, rather than try to work with the preferences file directly. To start, try creating a new thread over in App Frameworks / Cocoa. If you don’t get any joy there, open a DTS tech support incident and talk to one of our AppKit specialists.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you, eskimo. You are very knowledable as always.


>Trying to work with preferences files directly is unreliable because the files are managed by a system process (

cfprefsd
) that holds a lot of internal state.


I definite agree with that.


Hmm... I'll go to App Frameworks/Cocoa. I already opened a DTS ticket to get to the bottom of this issue three weeks ago, though. I have nothing negative to say, but he isn't so helpful. That's why I have come here out of desperation.

Accessing Sandboxed Application Preference File
 
 
Q