Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-31-2010, 11:29 AM   #1
renaultssoftware
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!
__________________
Get Icon Creator and support me.

Last edited by renaultssoftware; 12-31-2010 at 11:37 AM.
renaultssoftware is offline   Reply With Quote
Old 12-31-2010, 11:40 AM   #2
renaultssoftware
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];
In the NotificationHandler, I check whether the notification is in the sharedUserDefaults:
Code:
- (void)handleNotification:(NSNotification *)note {
NSString * noteName = [note name];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"SubscribedNotes"] containsObject:noteName]) {
// handle notification appropriately, I have code for this
}
}
Should this work? Is this a good idea?

Thanks!
__________________
Get Icon Creator and support me.
renaultssoftware is offline   Reply With Quote
Reply

Tags
application initializing, cocoa xcode, messages, nsnotification, nsnotificationcenter

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 04:14 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.