2009-08-24 9 views
1

こんにちは私は、NSFileHandleのreadInBackgroundAndNotifyメソッドを使用して、ログファイルが更新されたときに通知を受け取ります。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"); 
} 

を。

答えて

3
  1. NSLogをstartReadingに追加して、呼び出されていることを確認してください。
  2. ログfh。私の推測では、それはnilです(あなたがMyTestApp.logをまだ作成していない可能性が高いためです)。
+0

返信ありがとうございます:) startReadingが実際に呼び出されています。私NSはfileHandleをログに記録し、これが返すものです: indragie

+0

私の問題を解決しました。シートウィンドウが実行ループをブロックしていました。 – indragie

関連する問題