|
|
#1 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
Initializing an app
Hey guys, I have a certain conundrum to figure out here.
I'm writing a 'service' app of sorts. Basically, it subscribes to [[NSWorkspace sharedWorkspace] notificationCenter] to monitor events. The problem is, I can't figure out how to make it subscribe to certain notifications, efficiently. The idea I've had so far is to use the AppDelegate's applicationDidFinishLaunching: message to set it up. I'd have an array of strings in [NSUserDefaults standardUserDefaults] that represent desired notifications. I'd let a helper object (NotificationHandler) that's part of AppDelegate be subscribed to these notifications. Here I'm having trouble figuring out how to add methods to the NotificationHandler and how to subscribe. Any ideas? Thanks in advance! Last edited by renaultssoftware; 12-31-2010 at 11:37 AM. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
OK, I think I got something better. Something like this:
Code:
NSNotificationCenter * workspaceNotification = [[NSWorkspace sharedWorkspace] addObserver:notificationHandler selector:@selector(handleNotification:) name:nil object:nil]; Code:
- (void)handleNotification:(NSNotification *)note {
NSString * noteName = [note name];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"SubscribedNotes"] containsObject:noteName]) {
// handle notification appropriately, I have code for this
}
}
Thanks! |
|
|
|
![]() |
| Tags |
| application initializing, cocoa xcode, messages, nsnotification, nsnotificationcenter |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|