Re: applicationDidHide - Not Getting Triggered?
Re: applicationDidHide - Not Getting Triggered?
- Subject: Re: applicationDidHide - Not Getting Triggered?
- From: Ken Thomases <email@hidden>
- Date: Sat, 19 May 2012 04:15:53 -0500
On May 19, 2012, at 3:48 AM, Jason Teagle wrote:
> Everything went fine (after I fixed an incorrect alloc), but it's what happens at the end of the app's (apparent) lifetime that has got me slightly bemused. I'm running this under the debugger, if that makes a difference.
>
> If I Command-Q the main window, the debug session terminates as expected. If I only click the close button, the window vanishes but debugging doesn't stop. It took me a few minutes to figure out that this wasn't something dumb I'd done, but standard Mac app behaviour, whereby it hides for fast startup next time rather than actually quits (I *think* I've got that right?).
>
> To confirm that that was what was happening, I tried to trap applicationDidHide: - so I literally added
>
> - (void)applicationDidHide:(NSNotification *)aNotification
> {
> }
>
> into the delegate's .m file. I'm confident that I don't need anything to match in the .h file as this is an override, and applicationDidFinishLaunching: isn't in the .h file either.
>
> I have a breakpoint in there (on a dummy variable initialisation), but it doesn't get hit when I click the main window's close button.
>
> Have I misunderstood something?
Hiding an app is a specific operation that's not related to quitting it or closing its last window. There's a Hide <App Name> menu item in the application menu (the one named after the application). It's also available from the Dock context menu. Also, when another app is active, the user can do Hide Others, which would hide your app.
*That* is when -applicationDidHide: would be called.
Closing the last window of an application doesn't automatically quit it unless the app delegate implements -applicationShouldTerminateAfterLastWindowClosed: to return YES. The app is still running and current. Its menu is shown in the menu bar and you can still use it. Among other things, you may use it to open a new document (assuming it is document-based).
Under Lion, there can be a disconnect between the apparent running state of your app and the real one. Lion may show an app as running when its process has actually been terminated. It may also make it seem that an app which had no windows open and was not current has quit when it's actually still running. In the first case, resources are freed up. It is assumed that the app can restore its state, so the illusion that it was running all along is harmless to the user. In the second case, the UI is simplified but "restarting" the app is basically instantaneous because it was always running.
For this to happen, your app has to claim to support automatic termination, either by putting the NSSupportsAutomaticTermination key in the Info.plist or by invoking -[NSProcessInfo setAutomaticTerminationSupportEnabled:].
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden