Are you terminating the app from Xcode? Alternatively, is sudden termination enabled in your Info.plist?
Either of these will cause a SIGTERM
signal to be sent to the application, terminating it immediately, with no chance for the NSApplication instance to send its delegate an applicationWillTerminate:
message. (This is the point of sudden termination: Your app dies instantly. You can turn it off and on programmatically for times when this would be bad.)
Try quitting your application within itself (the Quit menu item in your Application menu), or using the Dock to quit it (right-click on your application's tile and choose “Quit”). As long as sudden termination is disabled (or never was enabled), either of these will cause your application object to send the applicationWillTerminate:
message.
Also check that your delegate is getting sent other application-delegate messages, such as applicationWillFinishLaunching:
, and make sure you hooked up the outlet in the correct nib (your MainMenu nib).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…