Search code examples
macoscocoaosx-mavericks

applicationShouldTerminate: not called when application closed on the red X


I am new to OSX development. I have to run some code when the app is about to terminate. applicationShouldTerminate: runs when quit is selected from the menu or when I press Cmd Q but not when I close the app on the red X ball.

How do I do that?

thanks.


Solution

  • on osx, per default an app doesnt close when the main window/the last of the app's windows is closed.
    => An app can run without any windows open.


    if you want the X to close the app implement the appDelegate method applicationShouldTerminateAfterLastWindowClosed and return YES there!