Normal，You won't encounter this problem，Until you need to write a background program...
We all know that macOS has a global Dock，All running programs will be displayed on this thing，But if your program is a menu bar applet，Or a...input method，Then you definitely don’t want the icon of this app to be displayed on the Dock，Because this kind of app needs to run continuously in the background。
At this time we can write in Info.plist LSBackgroundOnly Field，This app will run in the background，No Dock icon，It will not be displayed in the switch option of cmd+tab。This is what the drop grid input method does，This is also the configuration in Apple's official example-but this has long been accompanied by a problem，That is if your app still needs to display the necessary settings interface，Then this interface will always be at the bottom of all windows，That is，The window was blocked as soon as it popped up。Even，In addition to standard windows，Any other warning popups，All can't be displayed，Unless a standard window appears first，And the user clicked anywhere in the window...
The above premises have caused many problems，I have to embed another app as a special setting software for the drop-off input method，Then use xpc communication between the two，Really desperate。
Until today TIL，I found out that it can be used NSApplication.shared.setActivationPolicy(.accessory) Dynamically change your run level in the program，You can dynamically modify yourself to be ordinary regular mode，Or backstage prohibited mode。Obviously，I also understand by looking at the code name，It turns out that this background mode，Is deliberately disallowing pop-up windows。
/* The application does not appear in the Dock and may not create windows or be activated. This corresponds to LSBackgroundOnly=1 in the Info.plist. This is also the default for unbundled executables that do not have Info.plists. */
case prohibited = 2
Obviously，If you declare that the program is a background program，Then all of its windows can't get the focus，I always thought this problem was a bug of macOS😅
Then，Is there any other plan? Really have，In addition to the two modes above，macOS actually provides a mode between the two，No icon is displayed like a background program，It can also get focus when necessary and pop-up windows like ordinary programs：
/* The application does not appear in the Dock and does not have a menu bar, but it may be activated programmatically or by clicking on one of its windows. This corresponds to LSUIElement=1 in the Info.plist. */
case accessory = 1
When necessary, the operating mode of the program is dynamically switched to accessory .。
of course，If the code is too troublesome，We can also directly change Info.plist，The LSBackgroundOnly ，To LSUIEelement ，.。
Reproduced Please keep the source and description link：https://www.logcg.com/archives/3531.html