Here's a little oddity that might either be me being foolish (again) or relate
to an open Radar. I'm inclined to the former because (according to my search
of this list, to see if anyone else was having the same problem) the Radar was
opened in 2011 - which should be enough time to squish the bug!
I'm trying to use NSDistributedNotificationCenter to communicate between two
apps. The app posting the notification does it as follows:
NSDistributedNotificationCenter *centre = [NSDistributedNotificationCenter
defaultCenter];
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber
numberWithBool:openDialogue] forKey:@"ShowMenuBar"];
[centre postNotificationName:@"SetMenubar" object:nil userInfo:dict];
NSLog(@"Posted Toggle Menu bar item");
And the app observing the notification has the observer set up in
applicationDidFinishLaunching, thus:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSDistributedNotificationCenter *centre = [NSDistributedNotificationCenter
defaultCenter];
[centre addObserver:self selector:@selector(setMenubar:)
name:@"SetMenubar"
object:nil];
setMenubar is as follows (just for completeness)
-(void)setMenubar:(NSNotification *) aNote
{
NSLog(@"Received Notification, setting menubar");
[self displayMenu:[[aNote.userInfo objectForKey:@"ShowMenuBar"]boolValue]];
}
When I flip the toggle, I see 'Posted Toggle Menu bar item' in Console, but
'Received Notification, setting menubar' doesn't reliably show. In fact, there
is a way of getting it to notice the notification. I can click somewhere in
the UI of the receiving app - but that rather defeats the purpose of using
NSDistributedNotificationCenter.
So, my questions are these:
Is this an existing problem and, if it is, does anyone know of a good
workaround?
Am I doing this right? Should I be building some kind of event loop and
polling to see if a Notification has been posted? I guess not - it'd be rather
wasteful!
Is applicationDidFinishLaunching the right place for this?
Any help that you can offer will be very gratefully received.
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]