问题描述
我有一个应用程序,允许用户使用启动器应用程序通过首选项启用登录时打开"(请参阅 https://en.atjason.com/Cocoa/SwiftCocoa_Auto%20Launch%20at%20Login.html ).但是,当我选中该复选框以启用它时,启动器应用程序将打开我的应用程序的另一个实例.
I have an app for which I allow the user to enable 'open at login' via a preference using a launcher app (see https://en.atjason.com/Cocoa/SwiftCocoa_Auto%20Launch%20at%20Login.html). However, when I check the box to enable it, the launcher app opens another instance of my app.
推荐答案
我找到了可用于此目的的捆绑包钥匙: LSMultipleInstancesProhibited
.设置为 YES
时,无法打开另一个实例.潜在的不利之处在于,它还禁止另一个登录用户同时打开该应用程序.
I found a bundle key that can be used for this: LSMultipleInstancesProhibited
. When set to YES
, another instance cannot be opened. Potential downside is that it also prohibits another logged-in user from opening the app at the same time.
此处提供更多详细信息: https://developer.apple.com/库/内容/文档/常规/参考/InfoPlistKeyReference/Articles/LaunchServicesKeys.html
Further details available here:https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html
这篇关于如何防止我的macOS应用同时运行多个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!