Custom app not reading prefs since upgrade to Sonoma

Since upgrading to macOS Sonoma, having an issue with app prefs with a custom app I have been working on. The prefs are being read from some location I cannot determine, yet prefs are being written to the usual Library->Containers->[app]->...->Preferences. If I edit the prefs plist in Preferences, the change is not reflected when I restart the app; but, if the app makes changes to prefs, the prefs plist in Preferences is overwritten.

Replies

Quoting the NSUserDefaults documentation:

Important

Don’t try to access the preferences subsystem directly. Modifying preference property list files may result in loss of changes, delay of reflecting changes, and app crashes. To configure preferences, use the defaults command-line utility in macOS instead.

Thank you for your reply, JWWalker; your answer nips my question in the bud; it looks like I am doing something that I am not supposed to do. However, in macOS Monterey (before upgrading to Sonoma) I was able to modify the app's preferences plist, restart the app, and it all worked. Something in Sonoma broke what used to work (not surprisingly).

I did recently notice the following error message in the log:

Couldn't read values in CFPrefsPlistSource<0x600000314360> (Domain: com.[domain].[app], User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: Yes): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access

It looks like a sandboxing problem, but I haven't found an option in the app's Xcode project to alleviate the problem (and my knowledge runs shallow there).

Regardless, it looks like it's time to write my own "preferences" class. My app uses Preferences sort of as a mini database (nothing requiring a real SQL DB), and perhaps that's bad use as well. This is for a home-grown, home-use app, so between the sandboxing problem and the possibly inappropriate use of Preferences as a DB, I think I will write my own preferences/store class and make it work how I want and when I want.

Thank you again.