Settting up the observer code:
NSNotificationCente开发者_高级运维r *defaultCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[defaultCenter addObserver:self
selector:@selector(updateLog:)
name:@"Update Log"
object:nil];
Sending the notification code:
[[NSNotificationCenter defaultCenter] postNotificationName:@"Update Log" object:self];
With the method defined as:
-(void)updateLog: (NSNotification *) notification {
NSLog(@"Update Log"); }
The text "Update Log" does not appear in the log when the notification is sent. Thanks for any ideas for why this code is not working.
There is a difference between "the notification center for workspace notifications" Apple:
[[NSWorkspace sharedWorkspace] notificationCenter]
and "the process’s default notification center" Apple:
[NSNotificationCenter defaultCenter]
You need to pick one of those to use.
精彩评论