Display several system popups cocoa application

I have Cocoa application where I need to ask for recording and accessibility permission. I am seeing that only first feature asking for permissions shows its popup.

E.g If I put first code to ask for recording screen permission I dont see accessibility and in the Security and Privacy my app appears as I had rejected permission

Same happens on the other way around.

This is the code to request screen recording:

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


And this is the code for accessibility


NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
Boolean accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);

How can I fix this, please?

Thanks in advance and regards

No ideas or replies to this??? Is anyone else seeing this ?

Could you show more code, where you test and ask for (all) permission.

Hello,

Sorry for the late reply. I Have two functions which are called consecutively. Here is the code:


void MacUtils::checkIfScreenRecordingEnabledShowPopupIfNot()
{
    qInfo() << "MacUtils::checkIfScreenRecordingEnabledShowPopupIfNot()";
    CGDisplayStreamRef stream =
         CGDisplayStreamCreate(CGMainDisplayID(), 1, 1, kCVPixelFormatType_32BGRA, nil,
                               ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
                                 Q_UNUSED(status) Q_UNUSED(displayTime) Q_UNUSED(frameSurface) Q_UNUSED(updateRef) });
    if (stream)
       CFRelease(stream);
}


bool MacUtils::checkIfAccessibilityEnabledAndDisplayPopup()
{
    // Method to check if accessibility is enabled
    // Passing YES to kAXTrustedCheckOptionPrompt forces showing popup
    NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
    Boolean accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
    return (!!accessibilityEnabled);
}


First method is for screen recording permission, second one is for accessibility

If i call first method I see the popup asking for screen recording permissions but then I dont see accesibility popup and if I go to privacy menu it appears like if I had denied permission (app unchecked)

Do you have an idea how I can solve this?

Thanks in advance

I cannot understand from the code how all calls fit together, what is the sequence of call, if it occurs sync or async…


So, sorry, I give up on this.

In line 19, why are you using two not operators? Why not just return the bool, accessibilityEnabled, as is?

This is the complete example in Obj-C. Just in case you see something:

//
//  main.m
//  ScreenshotTest
//
//  Created by Raul Sanchez on 24/12/2019.
//  Copyright © 2019 Raul Sanchez. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreVideo/CVPixelFormatDescription.h>

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

bool checkIfAccessibilityEnabledAndDisplayPopup()
{
    // Method to check if accessibility is enabled
    // Passing YES to kAXTrustedCheckOptionPrompt forces showing popup
    NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
    Boolean accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
    return (!!accessibilityEnabled);
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Lets try this");
        showPopupIfNotSCreenRecording();
        checkIfAccessibilityEnabledAndDisplayPopup();
        NSLog(@"End of program");
    }
    return 0;
}

Hello,

I am using that !! in order to convert Boolean type to bool

Display several system popups cocoa application
 
 
Q