问题
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