Search code examples
cocoamacos

How to stop the termination of the application


I know that my question perhaps sounds a bit confusing, but I want to stop the terminating of a Cocoa Mac Os X application. I don't know if there is an API for that. And I also don't know how to do it.

My idea was to call an NSAlert inside the applicationWillTerminate: method. But that doesn't stop the termination of the App.

Another possibility would be to use a while loop, which doesn't stop, but this isn't good practice, because it uses a lot of CPU and doesn't add any possibility of keeping the rest of the app running.

Please give me an idea, how I could solve this problem.


Solution

  • Implement the application delegate method applicationShouldTerminate:. Return either NSTerminateCancel or NSTerminateLater. If you return NSTerminateLater then you should eventually call replyToApplicationShouldTerminate: with your final answer.