14

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?

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
bemul12
  • 413
  • 2
  • 4
  • 13

3 Answers3

16

macOS 11+

Apple now provides an API to determine if your app has Screen Recording access via CGPreflightScreenCaptureAccess() and also to request access via CGRequestScreenCaptureAccess(). Requesting access will present the system prompt and automatically add your app in the list so the user just needs to enable access. The system prompt will only appear once per app session. For an example, let's say they click Deny in the first prompt. If your app requests access again the prompt won't appear. But if they quit and relaunch your app, your app could request access again and the prompt would appear.

Original answer:

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.

Helpful testing info:

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.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • 2
    Don't use `All` use `ScreenCapture`. All resets many other things. – seth Oct 08 '19 at 02:05
  • 1
    I have called screen recording API in Agent app. When screen recording API invokes I am not getting any permission popup. While I am tried to debug code and I get pop up only on debug? – Sangram Shivankar Jan 08 '20 at 16:40
8

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.

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
Nic
  • 4,319
  • 5
  • 29
  • 36
  • 3
    I wish it would allow adding entries as well. For some reason, the app I'm using is not requesting permission anymore so I can't do screen sharing. What a mess At least this solution does clear permission values. Thanks – GabLeRoux Apr 03 '20 at 14:59
  • @GabLeRoux You tried every option in the linked answer? That process has helped me restore screen recording on every Catalina laptop I've encountered. If it still doesn't work for you, let's start a chat. – Nic Apr 03 '20 at 15:05
  • 1
    I managed to solve the issue I had with a reboot. For some reason, the app I was using never requested the permission and wasn't able to do screen sharing. I used `tccutil reset ScreenCapture All` and the bug applied to every other apps. I rebooted and now all apps asked for permissions again. "Sir did you try turning it off and on again?" worked – GabLeRoux Apr 03 '20 at 15:22
  • @GabLeRoux That's right. `tccutil` must be followed up by quitting each app. Rebooting is one way to do that. – Nic Apr 03 '20 at 15:27
  • Ah I did try to quit apps first. Didn't do it, but could be due to having some background worker process. I guess I should have tried something like `pgrep $appName | xargs kill`. – GabLeRoux Apr 03 '20 at 19:02
  • My problem is that my program isn't an app (its a LaunchdAgent) and has no bundle ID. I DO see it in "Privacy" system preferences panel, and I can turn on/off its screen-recording permissions - but I cannot use tccutil to remove it. I get this error every time: tccutil: No such bundle identifier "whatever I tried here": The operation couldn’t be completed. (OSStatus error -10814.) what to do? – Motti Shneor Jun 02 '20 at 17:55
  • @MottiShneor No bundle ID? That's not related to this answer, so you should probably ask that as a new question, either here on [StackOverflow](https://stackoverflow.com/questions/ask) or on the [Apple site](https://apple.stackexchange.com/questions/ask) where it's most on-topic. – Nic Jun 02 '20 at 18:10
-2

Try this: Shout down your Mac. Boot with Cmd+R Open terminal ..$ csrutil enable Reboot Mac

Talpik
  • 1