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");
}
但是選擇,不會被調用的通知沒有收到。
感謝您的回覆:) startReading確實被調用。我NSLogged the fileHandle,這就是它返回: –
indragie
2009-08-24 23:13:23
解決了我的問題。工作表窗口阻塞了運行循環。 – indragie 2009-08-26 17:50:24