Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger screen recording permission system modal dialog on macOS Catalina

I have an application which has screen sharing feature in it. On macOS Catalina beta8 (19A558d), you must give screen recording permission to share your screen (Without permission, only your background and menubar will be shared with the other side). Unfortunately, I really do not know which event or call triggers the system modal dialog, sometimes the dialog appears, sometimes it does not.

System modal dialog is shown on page 75 in wwdc macos security documentation:
https://devstreaming-cdn.apple.com/videos/wwdc/2019/701ngx868rfo8jlj/701/701_advances_in_macos_security.pdf?dl=1

So it is absolutely non-deterministic. Without interacting with this modal dialog, my application will not be registered under Security & Privacy / Screen Recording, thus I can not give permission for it. Does anybody have any idea, how can I solve this problem?

like image 826
bemul12 Avatar asked Sep 16 '19 12:09

bemul12


2 Answers

The screen recording prompt will appear only once - the first time you invoke an API that attempts to record the user's screen, such as:

CGDisplayStreamRef stream = CGDisplayStreamCreate(CGMainDisplayID(), 1, 1, kCVPixelFormatType_32BGRA, nil, ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
});
if (stream) {
    CFRelease(stream);
}

As you noted, your app won't appear in System Preferences under Screen Recording until you invoke a screen recording API thus triggering the system prompt.

If you trigger the prompt and the user denies it, you cannot bring up the prompt again - the user must manually enable it in System Preferences.

While building and testing this, you can reset your app's permissions as if you never invoked a screen recording API, via tccutil reset ScreenCapture com.company.appname. Or use All instead of ScreenCapture to reset all things permissions for your app.

like image 167
Jordan H Avatar answered Sep 27 '22 22:09

Jordan H


I answered this same question on Ask Different.SE. You need tccutil to reset these permissions.

Reset the privacy database for Screen Recording apps:

tccutil reset ScreenCapture

Or if you know the app bundle identifier, you can reset a single app.

tccutil reset ScreenCapture [com.WHATEVERBUNDLE.YOURAPPID]

Once you've reset the privacy permissions, you must quit your application before the change will take effect. Then you can restart your app and try screen recording again, and the prompt should reappear.

like image 28
Nic Avatar answered Sep 27 '22 20:09

Nic