ApplicationWillTerminate not called?

Newbie here.

I created a test MacOS application project in Objective-C. XCode generated the basic classes including AppDelegate. The documentation says that when the app quits then the applicationWillTerminate message is sent to the NSApplicationDelegate, which is where my app cleanup code should go. But when I choose "Quit" in the "File" menu neither applicationShouldTerminate nor applicationWillTerminate are called. The app just quits. What is wrong here?


By the way, applicationDidFinishLaunching is called, so I know my appDelegate object has been installed in the NSApp correctly.

Answered by john daniel in 414675022

The documentation is out of date. Modern Xcode templates default these values to true:

Application can be killed immediately when user is shutting down or logging out, and

Application can be killed to reclaim memory or other extraordinary circumstances


I think it is "Application can be killed immediately when user is shutting down or logging out" that causes the behaviour you describe.


Is your app a document-based project? Because documents never get deleted. Been that way for years.

Accepted Answer

The documentation is out of date. Modern Xcode templates default these values to true:

Application can be killed immediately when user is shutting down or logging out, and

Application can be killed to reclaim memory or other extraordinary circumstances


I think it is "Application can be killed immediately when user is shutting down or logging out" that causes the behaviour you describe.


Is your app a document-based project? Because documents never get deleted. Been that way for years.

I have tried a document-based project and one that is not document-based. Both exhibit the same behavior.

When do you suppose Apple will bring the API documentation up to date? Out of date API documentation is very misleading to anyone who is new to the API kits. It seems that they could at least mark these two methods "deprecated" and give a short explanation why.


BTW, thanks for your reply.

No, documents are something entirely different. I only mentioned it because it was a similar thing. You might be expecting to have your document objects deallocated at some point.


I specifically told you the setting that you can change to restore the old behaviour.


Apple will never bring the documentation up to date. All of macOS is pretty much deprecated. If you want any documentation for modern APIs, your best bet is to look in the headers. Now is not a good time to be new to macOS development. I suggest you focus on iOS instead.

ApplicationWillTerminate not called?
 
 
Q