1

I am testing accessibility permissions using AXIsProcessTrustedWithOptions.

When app starts, value is correctly returned. However if I change the setting in System Preferences -> Security & Privacy while app is running call to API is still returning the previous value.

Is that a bug?

Here is example code:

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(@"Starting");
       for (int i=0;i<100;i) {
           checkIfAccessibilityEnabledAndDisplayPopup();
           [NSThread sleepForTimeInterval:20.0f];
           NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @NO};
           Boolean b = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
           Boolean b1 = AXIsProcessTrusted();
           NSLog(@"accessibility AXIsProcessTrustedWithOptions--> %d AXIsProcessTrusted ---> 
           %d", b, b1);
       }
}
RuLoViC
  • 825
  • 7
  • 23
  • 1
    See [my answer](https://stackoverflow.com/a/61890478/581190) (sort of related) - things can get messy, especially on a dev machine. Anyway the recommended way is to tell the user to enable it and relaunch the application in case it wasn't enabled. It's a buggy mess. – zrzka Aug 06 '20 at 07:17
  • For me it helped checking in a separate thread using NSTimer. – Lenar Hoyt Jul 24 '22 at 12:46

0 Answers0