Using NSApplicationActivationPolicyAccessory does not hide the icon in dock

I have an application which will launches another application as a child process.

The child application does not need the dock icon, we use [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory]; to achieve it.

However, I have discovered that the dock icon cannot be perfectly hidden.

  1. The number of recently used apps that aren’t already in dock(not choose keep in dock) less than three: The icon of the child application remains in the dock without being hidden.

  2. The number of recently used apps that aren’t already in dock(not choose keep in dock) more than three: The icon of the child application appears a few milliseconds.

Even though add LSUIElement key in the Info.plist can work, we are seeking a programmatic modification.

Even though add LSUIElement key in the Info.plist can work

That’s definitely the option I recommend (or LSBackgroundOnly, depending on whether you show any UI or not).

we are seeking a programmatic modification.

Why?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

At what point in the app's lifecycle are you calling -setActivationPolicy:?

After create the app instance.

A sample demo code:

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSApplication *app = [NSApplication sharedApplication];
        BOOL returnValue = [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory];
    }
    return  NSApplicationMain(argc, argv);
}
Using NSApplicationActivationPolicyAccessory does not hide the icon in dock
 
 
Q