nsnotifications

Best practices for passing data between processes in Cocoa

I am in the middle of solving a problem which requires me to do the following in my 64-bit Cocoa application: Spawn a 32-bit Cocoa helper tool (command line tool) from within my application. This helper will open a file (a quicktime movie to be precise) and access information about that file using 32-bit only APIs (Quicktime-C APIs) T...

How can I get notified of a system time change in my Cocoa application?

I have a Cocoa application that records datestamps on events. I need to know when the system time is reset and by how much, but I can't seem to fine a notification anywhere that tells me such a thing has happened. This change could happen because NTP reset the clock or because the user reset (e.g. from System Preferences). It would be gr...

How to specify notificationSender? (Cocoa Touch)

All of the examples I can find of setting up a notification look like this: [nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil]; where object is always being set to nil. object is the notificationSender, which is defined thusly in the documentation: "The object whose notification...

Do I need a protocol for notification?

I have classDownload that uses NSURLConnection. I'd like to keep all of the NSURLConnection events in classDownload. ClassA wants to use classDownload but also receive notifications such as connectionDidFinishLoading, which is called Finish in classDownload. How do I get the notifications from classDownload over to ClassA? ...

Best way to post NSNotification with NSRect info?

Hi, what is the best way to post a notification with NSRect info? Here is my current solution (using NSStringFromRect). - (void)postNotificationForDirtyRect:(NSRect)rect { NSDictionary *userInfo = [NSDictionary dictionaryWithObject: NSStringFromRect(rect) forKey: ILDirtyRect]; NSNotificationCenter *ncenter...

Do I need to autorelease an object before sending it to NotificationCenter as a userdata?

I need to post a notification using postNotificationName:object:userInfo: method, and I'm passing a custom class FileItem in as userInfo so I can obtain it on the other end. Should I use autorelease like this FileItem *item = [[[FileItem alloc] init] autorelease]; [[NSNotificationCenter defaultCenter] postNotificationName:@"dataReceive...

NSNotificationCenter: Do objects receive notifications on the same thread they are posted?

I am interested in knowing whether I can expect the observing object's method to be pushed onto the stack before the posting object's method has been completed and removed. ...

How to use parametrized method with NSNotificationCenter?

I'd like to pass dict to the method processit. But once I access the dictionary, I get EXC__BAD_INSTRUCTION. NSNotificationCenter *ncObserver = [NSNotificationCenter defaultCenter]; [ncObserver addObserver:self selector:@selector(processit:) name:@"atest" object:nil]; NSDictionary *dict = [[NSDictionary alloc] ...

NSNotification Strangeness when used in conjunction with AsyncSocket

I'm using AsyncSocket to connect to a server from my iPhone App. In the delegate that received data from the server, I post a notification that would tell the tableView's delegate to trigger a reloadData on the tableView: - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData*)data withTag:(long)tag { [[NSNotificationCenter defau...

NSNotificationCenter selector won't work with its NSNotification

I'm working on a Cocoa project with some C in it (I know, objc contains C...) and am trying to understand NSNotificationCenters. Here's the situation: I have a struct declared as typedef struct {/*code here*/} structName; In my - (id)init method, I have [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selName...

Enforcing that a class posts a particular NSNotification?

Is there any way to ensure that a class posts a particular NSNotification? (I have a set of classes, and I would like to enforce at compile-time (if possible) that the class posts a required NSNotification). Alternatively, if that is not possible, is there any workaround? ...

UIViewController remove from superview after receiving nsnotification

Hello, i'm trying to remove a UIViewController from the superview after receiving a notification but it doesn't work. in my appDelegate i do something like this: - (void)applicationDidFinishLaunching:(UIApplication *)application{ NSLog(@"applicationDidFinishLaunching"); [window addSubview:tabBar.view]; splash = [[SplashViewControll...

How to block until certain notification is posted in Cocoa?

What's the best way to sleep/wait until certain notification is posted? I've got class with asynchronous API that gets data from NSNotification (notification comes from Cocoa, I can't avoid it) and I need to unit test it. So far I've figured out semi-busy wait: [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow...

NSFileHandle readInBackgroundAndNotify does not work

Hi I'm using NSFileHandle's readInBackgroundAndNotify method to get notifications when a log file has been updated. I have the following code: - (void)startReading { NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Logs/MyTestApp.log"]; NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:logP...

notification for touches ended

Hi, I am a little newbie regarding notifications on the iPhone. What I am trying to do is this: I have an object using a class based on UIImageView. This class has its own implementations of touchbegan, touchesended, etc. Is that possible for the main program to know when the user lifted his finger from the object? In other words, is...

Registering a Notification in iPhone SDK 3.0

Hi, In iPhone SDK 3.0, I would like to register for a notification, which would alert my application when a certain time is reached. Is it possible? Thanks ...

Why is my value passed through NSNotifcationCenter not preserved?

I'm trying to send a CGPoint through an NSNotification like this -(void)setPosition:(CGPoint)point { NSString *pointString = NSStringFromCGPoint(point); NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"p", pointString, nil]; [[NSNotificationCenter defaultCenter] postNotificationNa...

How to find out what UITextField caused a UIKeyboardWillShowNotification?

I am trying to use a customized keyboard in my application, but I am hitting problems when trying to restrict it to one particular UITextField. I based my code on this Xcode project (originally found on this blog). That code adds a custom UIButton (representing a 'decimal point') into the UIKeyboardTypeNumberPad keyboard view. It does...

Global Mouse Moved Events in Cocoa

Is there a way to register for global mouse moved events in Cocoa? I was able to register for the events using Carbon's InstallEventHandler(), but would prefer a Cocoa equivalent. I have looked for NSNotificationCenter events, but there doesn't seem to be any public event names (are there private ones?) Alternatively, is there a way to ...

How to add a notification for pop view controller in iphone application?

I have seen the sample application of iPhone MP-movie player - controller. They have added a notification on the sample code. // Register to receive a notification that the movie is now in memory and ready to play [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMovieP...