setActivationPolicy irregularities

The documentation still says NSApp.setActivationPolicy(.regular) is supported, but not NSApp.setActivationPolicy(.accessory). Obj-c header says that after 10.9, there are no restrictions on this (i.e. you can change policy to and from accessory). I've been targeting 10.11, so no problems expected.


While working on a project with the beta/initial releases of Xcode 8/Swift 3, it all seemed to go fine. I came back to work on the project now and it all seems to have gone south. Now, when I switch the app via NSApp.setActivationPolicy(.accessory) and later try to change it back via NSApp.setActivationPolicy(.regular), it fails. The result of setActivationPolicy(.regular) is false.


Am I correct that header notes are supposed to be the most accurate description of APIs in question?

Did Apple change the behavior of this API again?

Did Apple subtly change the behavior of this API just for Swift?


Thanks

Sad to say, these issues persist even now with Xcode 12.5.1 and MacOS 11.4

It sure looks like a bug, because alternative APIs to achieve more-or-less the same, are still supported and seem to work.

In my current code I use the combination of:

    ProcessSerialNumber psn = { 0, kCurrentProcess };
    TransformProcessType(&psn, kProcessTransformToForegroundApplication);
    [[NSRunningApplication currentApplication] unhide];
    [NSApp activateIgnoringOtherApps:YES];

As alternative to the always failing

    if ( [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular] == NO)
        os_log_error(preventionUILog, "Failed to change ActivationPolicy to Regular");

Hope this helps somehow...

setActivationPolicy irregularities
 
 
Q