I had a need tonight to observer all notifications being posted inside an application… it turns out it's pretty simple.
You first need to set your object up as an observer:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(log:) name:nil object:nil];
Note that the (notification) name is set to 'nil'.
Then you need to add the selector to actually log the notifications:
- (void)log:(NSNotificationCenter *)note {
NSLog(@"note = %@", note);
}
… and that's it!
I actually found the code to do this (or something like it) on this page at CocoaDev, so the credit goes to whoever wrote it there.








0 Responses to “Cocoa: Listen to all application NSNotifications”
Leave a Reply