If your application has an open TCP connection to a server and you receive anapplicationShouldTerminate:
message, you're likely to want to returnNSTerminateLater
so that you can first gracefully shut down the connection before quitting.There is a gotcha: returning
NSTerminateLater
stops the main runloop, so yourNSTimers
will stop working from that point on. Thus, if you were depending on a timer firing to finish up your shut-down process, you'll never see it, and you'll hang. The solution is to returnNSTerminateCancel
, then do whatever you need to do and then terminate yourself manually. (Thanks to Larry Gerndt for this one!)