首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSFileHandle readInBackgroundAndNotify不工作

NSFileHandle readInBackgroundAndNotify不工作
EN

Stack Overflow用户
提问于 2009-08-24 19:09:54
回答 1查看 1.8K关注 0票数 1

您好,我正在使用NSFileHandle的readInBackgroundAndNotify方法来获取更新日志文件时的通知。

我有以下代码:

代码语言:javascript
复制
- (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");
}

但是,选择器永远不会被调用,通知也不会收到。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-08-24 22:53:30

  1. 将NSLog添加到startReading以确保它被调用。
  2. 日志fh。我猜测它是nil (很可能是因为您还没有创建MyTestApp.log )。
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1324152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档