I want to quit the application only at the event of restart / logoff. Is there any way to find logoff/restart in OSX ?
Thanks in advance.
You can add an observer on
NSWorkspace watching for
NSWorkspace.shared().notificationCenter.addObserver(self, selector: #selector(yourMethod), name: .NSWorkspaceWillPowerOff, object: nil)
yourMethod will be called whenever the Mac is powering off (reboot or shutdown).
There's also notifications for going to sleep:
NSWorkspaceWillSleep and for waking up: