I have a two simple applications that use a NSConnection object for communication.
Now I need to terminate one of the apps in a controlled fashion, so I call -[MyObj terminate] on the vended object of the NSConnection. This method in turn calls -[NSApplication terminate:].
This causes the application to exit... But! Without ever calling -applicationWillTerminate: (or the "should" version either).
When calling -[NSApplication terminate:] from a method that is not involved with NSDistantObjects the delegate methods do get called however.
Is this documented behaviour or a bug or something I am doing wrong?
What I would like to achieve is (ironically) to cancel the termination request in applicationShouldTerminate: in order to gracefully shut down the NSConnection at a later well-defined time where I am not fiddling with NSDistantObjects.
Asked
Active
Viewed 57 times
0

iolo
- 1,090
- 1
- 9
- 20
-
First, `-applicationWillTerminate:` and `-applicationShouldTerminate:` are methods on the application **delegate**, not the application object itself. Next, are you sure teh termination is "normal"? Have you tried breaking on all Objective-C exceptions or otherwise running under the debugger to be sure it's not, say, triggering an assert? Anyway, you could defer the call to `-terminate:` using `dispatch_after()` or `-performSelector:withObject:afterDelay:`. – Ken Thomases Dec 22 '14 at 02:45
-
Thx for the remark of the delegate methods, it was late when I wrote the question... I actually don't really know how to examine the crash. I have already tried to break on all exceptions and have sprinkled a few NSLog()s here and there. But I don't get anything after the terminate: call. Also sudden termination is turned off, but to no avail. – iolo Dec 22 '14 at 08:55
-
1You could try putting a breakpoint on `_exit()` (note the leading underscore). – Ken Thomases Dec 22 '14 at 19:52