views:

340

answers:

2

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:logPath];
    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter addObserver:self
               selector:@selector(getData:)
                name:NSFileHandleReadCompletionNotification
                 object:fh];
    [fh readInBackgroundAndNotify];

}

- (void) getData: (NSNotification *)aNotification
{
     NSLog(@"notification received");
}

However the selector is never called and the notification is not received.

+1  A: 
  1. Add an NSLog to startReading to make sure that's getting called.
  2. Log fh. My guess is that it's nil (most probably because you haven't created MyTestApp.log yet).
Peter Hosey
Thanks for the reply :) startReading is indeed being called. I NSLogged the fileHandle and this is what it returns:<NSConcreteFileHandle: 0x20031c2a0>
macatomy
Solved my problem. A sheet window was blocking the run loop.
macatomy
A: 

to PCWiz :

i am Giga .i have the same question ,now i still not solved this .

can you tell me ,how to receive the filehandle's NSFileHandleReadCompletionNotification .

please mail to me for your soluation .

thanks you !

Gigajin
My solution was just to remove whatever was blocking the run loop, which in this case was a sheet.
macatomy
Oh my goth! This is probably the most stupid answer in the most evil English I have ever seen on this website...
Time Machine