关闭窗口然后选择另一个应用程序时,Mac应用程序消失 [英] Mac app disappears when window is closed then another app is selected

查看:196
本文介绍了关闭窗口然后选择另一个应用程序时,Mac应用程序消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 11.4中创建了一个新的macOS项目,该语言为Swift,用户界面为SwiftUI.在不对项目中的代码进行任何更改的情况下,该应用将通过执行以下步骤从停靠区中消失:

  1. 通过运行Xcode项目启动Mac应用
  2. 关闭Mac应用程序的主窗口
  3. 选择另一个正在运行的应用程序,例如Safari
  4. 原始Mac应用程序从扩展坞中消失,无法访问它

如果打开Mac应用程序的窗口,则不会发生此行为.我可以选择其他正在运行的应用程序,然后再回到原来的Mac应用程序.

解决方案

此行为称为活动监视器中的进程列表真实反映了实际正在运行和未实际运行的情况.查看那里以确定您的应用是否真的终止了.

假定开发人员必须选择自动终止,因为它需要状态恢复的显式编码.但是,默认情况下,Xcode的应用程序项目/目标模板已启用它.您可以从Info.plist列表中删除NSSupportsAutomaticTermination键以将其禁用.

同样,如果您不准备支持突然终止",则可能也想禁用它.您将删除NSSupportsSuddenTermination键.

I created a new macOS project in Xcode 11.4 where the language is Swift and user interface is SwiftUI. Without making any changes to the code in the project, the app will disappear from the dock by performing the following steps:

  1. launch the Mac app by running the Xcode project
  2. close the main window of the Mac app
  3. select another running app such as Safari
  4. the original Mac app disappears from the dock with no way to access it

This behavior does not happen if the window of the Mac app is open. I can select other running apps then go back to the original Mac app with no problems.

解决方案

This behavior is known as Automatic Termination. I find it a misfeature, but Apple considers it a feature.

Your app may not have actually quit. It may just appear to have quit. "Launching" it again will just make it reappear in the Dock. It's also possible that some apps which look like they're still running have actually been terminated by the system. In theory, if you try to switch to them, they will be launched and told to restore their previous state to maintain the illusion that they were running all along. In practice, apps (even Apple's) rarely properly restore things to exactly how they were.

The process list in Activity Monitor is a true reflection for what is and is not actually running. Look there to determine if your app has really been terminated.

A developer is supposed to have to opt-in to Automatic Termination because it requires explicit coding of state restoration. However, Xcode's app project/target templates have it enabled by default. You can remove the NSSupportsAutomaticTermination key from your Info.plist to disable it.

Likewise, you'll presumably want to disable Sudden Termination, too, if you're not prepared to support it. You would remove the NSSupportsSuddenTermination key.

这篇关于关闭窗口然后选择另一个应用程序时,Mac应用程序消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆