简体   繁体   English

如何防止我的 macOS 应用程序同时运行多个实例?

[英]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.

相关问题 当应用程序在后台时,如何防止 iOS 关闭我的心率监测器? - How do I prevent iOS from closing my heart rate monitor when the app is in the background? 在同一个 Xcode 项目中拥有 iOS 和 macOS 应用程序 - Having iOS and macOS app in same Xcode project 我如何自定义在我的应用程序中运行AppleScript时出现的消息 - How do I customize the message that comes up on running AppleScript from within my app 使用XCode 8我如何将我的应用程序也定位为在macOS上运行(它已经在iPhone / iPad上运行)? - With XCode 8 How Do I Target My App To Run on macOS also (it already runs on iPhone / iPad)? 如何阻止我的游戏访问麦克风? - How do I prevent my Game from accessing Microphone? 为什么每次都要在模拟器中运行我的应用程序之前都要删除它? - Why do I have to delete my app every time before running it in the simulator? 如何在 MacOS 应用程序中禁用密码自动填充 - How do I disable the password autofill in MacOS app 如何延长我的配置证书对我的 iOS 应用程序的有效时间? - How do I extend the amount of time my provisioning certificate is valid for my iOS app? 你如何防止Xcode 7 Playgrounds自动运行? - How do you prevent Xcode 7 Playgrounds from automatically running? 如何从我的应用切换到地图以查找路线? - How do I switch from my app to map for directions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM