嗨,我正在使用 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");
}
然而,选择器永远不会被调用,也不会收到通知。