5

I am working on a screen recording app using C++ in XCode. The problem is that when I compile and start the app I always have to give permission for screen recording in "Settings > Privacy".

Is there a way to always grant the permission in XCode or sth similar? It is really annoying when developing/testing the app to always manually grant the permission when re-compiling.

4
  • It is indeed a big bother. But I don't think there is anything you could do about it unless you install Mojave on another drive and write code there. I wish I could go back to Mojave. But I can't.
    – El Tomato
    Commented Dec 5, 2019 at 15:37
  • 2
    Code sign your app (it should be sufficient to enable automatic signing in the project properties). As long as the bundle ID and code signature do not change, macOS will recognize that it's the same app every time.
    – TheNextman
    Commented Dec 5, 2019 at 16:34
  • I had a similar problem when writing sensitive data in the Keychain. Everytime you recompile, the system thinks of your app as a different app, so it asks again for permissions. You can fix this by code signing your debug builds.
    – Guilmo
    Commented Dec 5, 2019 at 19:37
  • @zhadar I have a similar Problem, but I never get asked, to give the permission and in Privacy Settings I cannot add my app to the list of apps, that are allowed to do screen recording. How can I get this permission.
    – mica
    Commented Dec 18, 2019 at 8:44

1 Answer 1

9

Sign your debug builds Luke

In order to grant macOS "Screen Recording" permission for development (or any other permission like microphone or camera access) you must sign your debug builds with your AppleID certificate. This applies for Swift/C++/Objective-C or any other language.

It's easy and free to do:

  1. Simply click at your project
  2. Go to "Signing & Capabilities"
  3. Select "Development" in "Signing Certificate"
  4. Pick your certificate in the "Team" (if you don't have any there will be an "Add Team" button which lets you download a free one after providing your AppleID)

After that your build settings should look like that: Properly configured build (you may need to go use Product -> Clean Build Folder and rebuild)

If permissions appears revoked...

Also if the system still doesn't give you permissions you need to go to system Settings -> Security & Privacy -> Privacy and under an appropriate category you need to REVOKE the permission and grant it again after rebuild. This will prompt for app quit - do it and run the application again. From now on it will always have permissions.

4
  • This does not work on Catalina. I have my code signing configured as you pointed out on the screenshot. It works for other permissions but not for Screen Recording. Every time the app is compiled, it prompts for permission again.
    – gcstr
    Commented Feb 12, 2020 at 0:18
  • 2
    I had this happen before. You may try to reset all privacy permissions using tccutil reset All. This method definitely works on Catalina, since Apple created this problem only on Catalina and in fact I encountered it on Catalina too ;)
    – kiler129
    Commented Feb 13, 2020 at 6:22
  • 1
    Thanks @kiler129, I tryed that too but with no success. The only thing that worked for me was to generate self-signed certificates and to set it up on the project instead of development.
    – gcstr
    Commented Feb 13, 2020 at 11:55
  • Just want to add something for others finding this: if you open a release build of your app (as in double click it from Finder) and then grant it permission, I have found that future builds in Xcode result in this issue. To avoid a tccutil reset I deleted the release .app from Finder (and emptied the trash), removed all instances of my app from Privacy settings and then clean-built in Xcode :) Commented Jul 3, 2022 at 6:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.