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