[英]How do I prevent my macOS app from having multiple instances running at the same time?
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 ).我有一个应用程序,我允许用户通过使用启动器应用程序的首选项启用“登录时打开”(请参阅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.但是,当我选中该框以启用它时,启动器应用程序会打开我的应用程序的另一个实例。
I found a bundle key that can be used for this: LSMultipleInstancesProhibited
.我找到了一个可用于此LSMultipleInstancesProhibited
的包键: LSMultipleInstancesProhibited
。 When set to YES
, another instance cannot be opened.设置为YES
,无法打开另一个实例。 Potential downside is that it also prohibits another logged-in user from opening the app at the same time.潜在的缺点是它还禁止另一个登录用户同时打开应用程序。
Further details available here: https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html此处提供更多详细信息: https : //developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.