Home > database >  CGPreflightScreenCaptureAccess always returns false in development builds
CGPreflightScreenCaptureAccess always returns false in development builds

Time:04-29

I'm writing an app for macOS (12.1 locally) in Xcode 13.2.1. I need screenshot access, and it seems like the easiest way to get permission for that (in macOS 11 and later) is to use CGRequestScreenCaptureAccess, and to check eligibility using CGPreflightScreenCaptureAccess:

Screenshot of app requresting recording permissions

and I'm able to see my app appear in System Preferences, also as expected: Screenshot of app in Screen Recording permissions section of System Preferences

Enabling my app's permissions prompts me to quit my app and restart it. This restarts my production copy of my app, from the app store. However, if I quit that and re-run the same build in XCode, my build is still not granted permission to record the screen (even though it appears as enabled in System Preferences). How do I allow my app to have permissions to record my screen locally?

CodePudding user response:

I solved this in the process of writing this question, so I figured I'd share my answer. If I delete the copy of my app from my Applications folder, things seem to work. I assume that there is some sort of "claiming" process that goes.

It seems to work if I rename the copy of the app in my Applications folder, delete the screen recording in System Preferences, and then run my fresh build from Xcode.

CodePudding user response:

We had a similar issue after renaming one of our apps which made use of the /usr/sbin/screencapture command line tool. The security prompt appeared every time a screen capture was triggered, no matter the activation status in System Preferences.

During development, the tccutil reset ScreenCapture {bundle identifier} command helped keep the permissions clean for subsequent testing.

  • Related