According to Apple's docs, closeAllDocumentsWithDelegate (from NSDocumentController) should call canCloseDocumentWithDelegate of NSDocument for all open documents if you quit an application.
In my NSPersistentDocument-based app I need to override canCloseDocumentWithDelegate in order to warn the user in case a certain server functionality is still running when the document closes. This has nothing to do with any data changes.
This works when the user closes a single document; I can present a sheet with the warning and let the user cancel the closing process.
However, my version of canCloseDocumentWithDelegate does not get called when the app is quit. What could be the reason for that?
According to Apple Developer Technical Support this is a known issue. I finally cut the automatic wiring of the app's quit menu item and handle it all by myself. I needed to make the server functionality information of the document available from the outside (in this example the state of
optionButton) and added this function to theAppDelegate:Then I bound the app's quit menu item to
terminateGracefully: