This is a hardened, sandboxed app as required for notarization
That doesn’t make sense:
Applying both of these options is a good idea security-wise, but it’s not a requirement.
The problem is that I receive an error indicating I cannot access the preferences file and that I need to set an entitlement user-preference-read but I cannot find this entitlement
There are no public sandbox entitlements for accessing preferences. If you’re seeing a sandbox violation like this, something weird is happening.
What is the exact text of that message?
I supplied Apple with a simple test case
I got that, but I’m unable to build it because there’s no project file.
I was able to locate the user defaults code and it’s a pretty straightforward application of the API. Specifically, you’re using the standard user defaults, accessed via +[NSUserDefaultsController sharedUserDefaultsController]
. If you’re building a typical application, something that the user double clicks in the Finder, then this should work out of the box, without any special action on your part.
It is weird that you’re using NSUserDefaultsController
, rather than NSUserDefaults
, but there’s nothing fundamentally wrong with that.
To investigate further I:
-
Created a new test project from the macOS > App template. This defaults to having both the App Sandbox and the hardened runtime enabled.
-
Added your +initialize
method to the AppDelegate
delegate.
-
Set a breakpoint at the top of that method.
-
Ran your app on my Mac (I’m using Xcode 15 on macOS 14.5) and stepped through the code.
I didn’t notice anything weird. The code seemed to work as expected and there were no weird log messages.
I recommend that you repeat this test and see what you get.
IMPORTANT Give your new test project a new bundle ID. In my case I used com.example.apple-samplecode.Test60239
.
You didn’t respond to this point from my earlier post:
Might it be tied to your user account? If you run the app from the Finder on a ‘fresh’ machine, do you still see the problem? [1]
[1] I usually use a VM for this sort of testing, so I can restore from a snapshot between each test. If you don’t have a VM set up, the next best thing is to create a new user account.
Did you try this? What was the result?
There’s a reason I suggested this test. I suspect that the issue you’re seeing is tied to macOS 14’s app container protection [1]. It’s possible that there’s a mismatch between your app’s container setup on disk and the way that your app is now being signed. If you start on a fresh machine, or even with a fresh user account on your main machine, you’ll start with a fresh app container. If that doesn’t have the problem, it’s a good indication of where to investigate next.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] I have a link to the WWDC session that talks about this in Trusted Execution Resources.