Unexpected SIGKILL when privacy access to folder is unchecked


My application requires access to the Documents folder. As a result, the first time you launch the app, you get the privacy dialog that prompts you to give the application access to the Documents folder. If you hit OK, the checkbox appears enabled in privacy preferences. 

However, if I then uncheck that box and launch my app again, it gets killed right away. The system logs show access is denied for kTCCServiceSystemPolicyDocumentsFolder. This feels unexpected to me, because if the checkbox for Documents folder isn’t checked, shouldn’t things revert back to the original behavior, where the user is prompted for access? 

To summarize:

Expected behavior: Disabling access to Documents folder in privacy preferences and then launching the app should result in the privacy dialog appearing to request access from the user

Actual behavior: Disabling access to Documents folder in privacy preferences and then launching the app causes a SIGKILL to get sent to the app, so the app fails to launch without any user-facing error messages. In addition, if I remove all entries for the app in “Files and Folders” and “Full Disk Access” (in an attempt to revert back to the original prompting behavior), the same issue occurs. 

Is the behavior I am seeing by design? I realize I can manually reset the TCC database but would like to know if the behavior I am seeing is intentional or not.


However, if I then uncheck that box and launch my app again, it gets killed right away.

I agree that this is unexpected. I repeated your test here in my office and it’s not what I saw. Specifically, I created a new test app and added this code to access Documents:

Code Block
do {
print("will get doc dir")
let docDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
print("will list doc dir")
let docContents = try FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil, options: [])
print("did list doc dir, contents: \(docContents)")
} catch {
print(error)
}


When I ran the app after revoking the app’s access to Documents, I saw this:

Code Block
will get doc dir
will list doc dir
Error Domain=NSCocoaErrorDomain Code=257 "The file “Documents” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///Users/quinn/Documents, NSFilePath=/Users/quinn/Documents, NSUnderlyingError=0x600000cb6130 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}


This is what I expected: The app isn’t killed, but rather the file system API fails with an error.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

WWDC runs Mon, 22 Jun through to Fri, 26 Jun. During that time all of DTS will be busy with conference duties.
Unexpected SIGKILL when privacy access to folder is unchecked
 
 
Q