简体   繁体   English

使用LSUIElement设置的Mac应用程序,如何选​​择显示Dock图标?

[英]With a Mac app that LSUIElement set, how can I optionally show the Dock icon?

I'd like my Mac App which is a menubar-only app to optionally also show a Dock icon, so users can click the Dock icon to show the user interface of the app. 我希望我的Mac App(仅菜单栏应用程序)也可以选择显示Dock图标,因此用户可以单击Dock图标以显示该应用程序的用户界面。

The reason for this is that it confuses new users when they launch the app for the first time—only a menubar icon shows up, and no Dock icon. 这样做的原因是,新用户在首次启动应用程序时会感到困惑-仅显示菜单栏图标,而没有Dock图标。 Some users assume the app doesn't work or has crashed. 一些用户认为该应用程序无法运行或崩溃。

How can I still show the Dock icon even with LSUIElement=1 set? 即使设置了LSUIElement = 1,如何仍然显示Dock图标?

You can change the activationPolicy of the application object to make it a regular app (with a Dock icon and main menu), like so: 您可以将应用程序对象的activationPolicy更改为常规应用程序(带有Dock图标和主菜单),如下所示:

[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

Since 10.9, you can also switch it back (without quitting and relaunching) to NSApplicationActivationPolicyAccessory . 从10.9开始,您还可以将其切换回NSApplicationActivationPolicyAccessory (无需退出并重新启动)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM