Skip navigation.
 
mlRe: Performing actions before logging out
FROM : Scot Gellock
DATE : Wed Jan 01 16:38:40 2003

On 12/31/02 6:43 AM, "Arthur VIGAN" <arthur.<email_removed>> wrote:

> Hi,
>
> I have an application which is a just a front-end to a background
> process, but I have a little problem when I logout. To quit my
> application I use a custom method which finishes by [NSApp
> terminate:nil], and everything works fine. But when I logout, this
> method is not called, and so the background processed isn't killed.
> So my question is: how can I call my quitting method when a "logout
> signal" is received?
>
> Thanks in advance,
>
> Arthur
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.


Logout and system shutdown comes to you as an event.  You need to add an
observer to the notification center.  Here is some quick sample code:

NSNotificationCenter *nc;


nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
      selector:@selector(workspaceWillPowerOff:)
          name:@"NSWorkspaceWillPowerOffNotification"
        object:nil];


The code for the event handler is as follows.  The code just tosses up a
alert panel for demonstration purposes:


- (void)workspaceWillPowerOff:(NSNotification *)aNotification
{
    // you can get the NSWorkspace object
    // in the following manner:
    //
    // NSWorkspace *myWorkspace;
    // myWorkspace = (NSWorkspace *)[aNotification object];
    //

    NSRunAlertPanel(@"MyDocument",
        @"inside my document's workspaceWillPowerOff",
        nil, nil, nil);
}


Scot
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlPerforming actions before logging out Arthur VIGAN Dec 31, 15:43
mlRe: Performing actions before logging out David Rio Vierra Dec 31, 15:53
mlRe: Performing actions before logging out Scot Gellock Jan 1, 16:38