I'm developing application for macOS which require screen recording. Each time when I will recompile code, I have to manually add exception for this application in Security & Privacy (Screen Recording tab). Is there a way, to allow it only once?
I was trying to acces it using this code:
if( !CGPreflightScreenCaptureAccess())
{
print("not granted!")
let result = CGRequestScreenCaptureAccess()
if(result == true)
{
print("Screen recording granted, thank you.")
}
else
{
print("Not granted! Bye-bye...")
exit(1)
}
}
but CGRequestScreenCaptureAccess does not wait for approval.
I was also trying to poll current status by calling CGPreflightScreenCaptureAccess in a loop, but it always returned false, even after manual approval.
When I run this application from terminal (which have pernament access to screen), everything is working fine. But this way, I cannot debug anything.