1

こんにちは私は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");
}

ただし、セレクターが呼び出されることはなく、通知は受信されません。

4

1 に答える 1

3
  1. NSLogをに追加して、呼び出されstartReadingていることを確認します。
  2. ログfh。私の推測では、それはnil(おそらく、MyTestApp.logをまだ作成していないためです)。
于 2009-08-24T22:53:29.807 に答える