If your application has an open TCP connection to a server and you receive an
applicationShouldTerminate:message, you're likely to want to return
NSTerminateLaterso that you can first gracefully shut down the connection before quitting.
There is a gotcha: returning
NSTerminateLaterstops the main runloop, so your
NSTimerswill 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 return
NSTerminateCancel, then do whatever you need to do and then terminate yourself manually. (Thanks to Larry Gerndt for this one!)