您好,我正在使用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");
}但是,选择器永远不会被调用,通知也不会收到。
发布于 2009-08-24 22:53:30
startReading以确保它被调用。fh。我猜测它是nil (很可能是因为您还没有创建MyTestApp.log )。https://stackoverflow.com/questions/1324152
复制相似问题