Re: App startup/shutdown hooks
Re: App startup/shutdown hooks
- Subject: Re: App startup/shutdown hooks
- From: Damien Bobillot <email@hidden>
- Date: Tue, 4 Oct 2005 17:56:05 +0200
Neil Baylis wrote :
Here's my main, generated by interface builder, with printouts added.
int main(int argc, char *argv[])
{
int retval;
printf("App starting\n");
retval = NSApplicationMain(argc, (const char **) argv);
printf("App exiting\n");
return retval;
}
When I run it, the first printout prints fine, and the app runs as
expected. The window comes up and works correctly. When the app exits,
(by closing it from the gui) the second printf never prints. If I put
a breakpoint there, it never hits. This is probably very basic, but..
what's going on here?
The NSApplicationMain method only returns if you call the stop:
method of the main NSApplication object, not if someone call the exit
() function : -[NSApplication terminate:] call exit().
What is the correct way for me to execute some cleanup code when the
application exits?
There's many solutions :
- catch the NSApplicationWillTerminateNotification notification
- override the applicationShouldTerminate: methode in your
application class
- use atexit() : it will work even if you emergency quit your program
with a call to exit()
--
Damien Bobillot
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden