简体   繁体   English

如何防止注销以代理身份运行的应用程序

[英]How to prevent logout from app running as agent

The sample menu bar app is a agent as its LSUIElement is TRUE. 样本菜单栏应用程序是一个代理,因为其LSUIElement为TRUE。 I want to prevent logout on certain conditions. 我想防止在某些情况下注销。

I tried with - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender. 我尝试使用-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender。 But I never receive this message when user logs out. 但是当用户注销时,我从未收到此消息。

But without , I am able to prevent logout as well. 但是,如果没有,我也可以防止注销。

Need an alternative solution so as to prevent logout. 需要替代解决方案,以防止注销。

Do not use LSUIElement in the plist. 不要在plist中使用LSUIElement。 Instead on launch use: 而是在启动时使用:

[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];

I verified that applicationShouldTerminate: is in fact called when done this way. 我验证了applicationShouldTerminate:实际上是通过这种方式调用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 阻止“ performSelectorInBackground:”运行两次? - Prevent `performSelectorInBackground:` from running twice? 如何从NSApplication运行启动的代理/守护程序? - How to run launchd agent/daemon from a NSApplication? 可可菜单栏代理应用程序具有助手可可应用程序并从主可可应用程序触发打开后,其响应时间为 - Cocoa Menu Bar Agent app With a Helper cocoa app and triggered ON from Main cocoa app, its Gone in NOT RESPONDING 如何防止在启动情节提要应用程序时显示NSWindow? - How to prevent NSWindow showing on launch of a storyboard app? 防止多个用户同时在macOS上运行应用程序 - Prevent multiple users from running application simultaneously on macOS 如何防止NSCursor改变? - How to prevent a NSCursor from change? LSUIElement代理应用更新核心数据后,如何通知另一个应用? - After LSUIElement agent app updating core data, how can another app be notified? 防止基于 NSDocument 的应用程序在崩溃后重新打开文档 - Prevent NSDocument-based app from reopening documents after a crash 即使应用程序是代理,如何在按Ctrl-Tab时强制显示窗口 - How to force windows to appear when pressing Ctrl-Tab, even though app is agent 防止在OSX 10.8应用程序启动时打开iCloud窗口 - Prevent iCloud window from opening on OSX 10.8 app launch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM