我有一个基于 NSDocument 的应用程序。我想知道应用程序何时将退出以验证某些内容。我希望可能有一种方法,例如 applicationWillQuit,但是查看 NSDocument 和 NSApplication 的文档我找不到类似的东西。
问问题
4372 次
2 回答
12
There is a notification you can use coming from your NSApplication:
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(appWillTerminate:)
name:NSApplicationWillTerminateNotification
object:nil];
This is documented here: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nsapplication_Class/Reference/Reference.html
By passing the object as nil
your method is being called whenever an object fires the notification.
于 2013-02-10T13:46:33.977 回答
-1
我们在AppDelegate.swift或AppDelegate.m类中有一个委托方法。您可以在关闭它之前使用它并向您的应用程序添加功能。
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
于 2020-11-07T07:50:55.693 回答