如何防止我的macOS应用同时运行多个实例? [英] How do I prevent my macOS app from having multiple instances running at the same time?

查看:92
本文介绍了如何防止我的macOS应用同时运行多个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,允许用户使用启动器应用程序通过首选项启用登录时打开"(请参阅​​

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应用同时运行多个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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