How to prevent logout from app running as agent

307 Views Asked by At

The sample menu bar app is a agent as its LSUIElement is TRUE. I want to prevent logout on certain conditions.

I tried with - (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.

1

There are 1 best solutions below

3
user3555093 On

Do not use LSUIElement in the plist. Instead on launch use:

[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];

I verified that applicationShouldTerminate: is in fact called when done this way.