我怀疑会有一个分布式通知通知应用程序,所以我写了一个小 Obj-C 应用程序......
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
@autoreleasepool
{
[[NSDistributedNotificationCenter defaultCenter]
addObserverForName: nil
object: nil
queue: [NSOperationQueue mainQueue]
usingBlock: ^(NSNotification *notification) {
NSLog(@"Got a notification %@", notification);
}];
[[NSRunLoop mainRunLoop] run];
}
}
我收到了这些通知
05/12/2012 19:17:12.044 Untitled 2[62058]: Got a notification __CFNotification 0x7ffd98e04900 {name = com.apple.logoutInitiated; object = 501}
05/12/2012 19:17:22.376 Untitled 2[62058]: Got a notification __CFNotification 0x7ffd98c0c580 {name = com.apple.shutdownInitiated; object = 501}
05/12/2012 19:17:22.388 Untitled 2[62058]: Got a notification __CFNotification 0x7ffd98c0b8f0 {name = com.apple.logoutContinued; object = 501}
com.apple.logoutInitiated
对应于“关闭”对话框的打开,并且
com.apple.shutdownInitiated
按下按钮时收到。
现在,当然你不会知道关闭是否真的会发生,一个应用程序可以取消关闭。不过,您可能也会收到通知。