简体   繁体   中英

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 ). 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 . 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM