I've been having some trouble with Snow Leopard's new block-based API for observing notifications from NSWorkspace's NSNotificationCenter.
If I register for notifications using the traditional selector-based method, then I am able to observe the desired notification. If I try using the new method that takes a block, then it doesn't work.
In the code block below, setting usingBlockNotifications to either YES or NO should produce the same result, i.e. "didReceiveNoticationTest: called" printed to the console when an app launches, but I don't get the message when it's set to YES.
Any suggestions on what I'm doing wrong?
-(void)awakeFromNib
{
BOOL usingBlockNotifications = YES;
_notifcationObserver = nil;
NSNotificationCenter *nc = [[NSWorkspace sharedWorkspace] notificationCenter];
if (usingBlockNotifications)
{
_notifcationObserver =
[nc addObserverForName:NSWorkspaceDidLaunchApplicationNotification
object:[NSWorkspace sharedWorkspace]
queue:nil
usingBlock:^(NSNotification *arg1) {
[self didReceiveNoticationTest:arg1];
}];
[_notifcationObserver retain];
} else {
[nc addObserver:self
selector:@selector(didReceiveNoticationTest:)
name:NSWorkspaceDidLaunchApplicationNotification
object:[NSWorkspace sharedWorkspace]];
}
}
-(void)didReceiveNoticationTest:(NSNotification *)notification
{
NSLog(@"didReceiveNoticationTest: called");
}