How do I prevent my macOS app from having multiple instances running at the same time?

安稳与你 提交于 2020-07-09 06:46:34

问题


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.


回答1:


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.

Further details available here: https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html



来源:https://stackoverflow.com/questions/46577414/how-do-i-prevent-my-macos-app-from-having-multiple-instances-running-at-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!