NSFileHandle readInBackgroundAndNotify не работает - PullRequest
1 голос
/ 24 августа 2009

Привет! Я использую NSFileHandle метод readInBackgroundAndNotify, чтобы получать уведомления об обновлении файла журнала.

У меня есть следующий код:

- (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");
}

Однако селектор никогда не вызывается и уведомление не принимается.

1 Ответ

3 голосов
/ 25 августа 2009
  1. Добавьте NSLog в startReading, чтобы убедиться, что он вызывается.
  2. Журнал fh. Я предполагаю, что это nil (скорее всего потому, что вы еще не создали MyTestApp.log).
...