Understanding CGRequestScreenCaptureAccess()

CGRequestScreenCaptureAccess() and CGPreflightScreenCaptureAccess() should return true or false depending on whether the app has screen recording permission. CGRequestScreenCaptureAccess() will bring up a dialog if there is no permission. The dialog directs the user to the System Settings, where the permission can be set.

CGRequestScreenCaptureAccess() returns immediately in any case. If it brings up a dialog, that happens from a separate process (Finder?) That dialog stays up even if the app quits before the dialog is dismissed.

Since CGRequestScreenCaptureAccess() returns immediately, I tried tracking the permission state by setting up a timer to repeatedly call CGPreflightScreenCaptureAccess() until the permission is set, but if it returned false to begin with, it will continue to return false, even if the app has been given permission for screen capture. Why is that?

When the permission to capture is set in the System Settings, a dialog says, "(App Name) may not be able to record the contents of your screen until it is quit." I imagine that is related to CGPreflightScreenCaptureAccess() keeping returning false. But why "may not be able"? When does the permission setting change take effect immediately? How can this be detected?

Replies

I imagine that is related to CGPreflightScreenCaptureAccess keeping returning false.

That’s right.

But why "may not be able"?

Because this is way more complex than you might think (-:

My experience is that a single user-visible privilege can cover multiple APIs. Some of their implementations react to change better than others, and in some cases it’s determined by how the app uses the API. Thus, the system can’t tell whether your app will or won’t see the new privileged immediately.

When does the permission setting change take effect immediately?

For don’t think it does for this specific subsystem.

Share and Enjoy

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

When does the permission setting change take effect immediately?

I don’t think it does for this specific subsystem.

It does, though! For the thing I am testing, and for other utilities, the change does take effect immediately, at least older ones using the Core Graphics API (specifically CGWindowListCreateImage()). The change in privileges is not reflectetd in the return value of CGPreflightScreenCaptureAccess, though.

In my application I am using CGRequestScreenCaptureAccess() to check screen the recording permission , Here can I modify the dialog box messages to show customized message to user ?

Can I remove the deny option button in dialog box ?