SCEvents 在某些方法中不起作用?
[注:标题可能不太准确,我不知道该怎么表达] 由于某种原因 NSFileHandle 的 readInBackground 不起作用,所以我求助于 SCEvents,它是 Mac OS X 的 FSEvents API 的 Cocoa 包装器。我有一个名为“EventListener”的单独类,用于处理所有 SCEvents 内容。
它有这些方法:(
- (void)setupEventlistener
{
SCEvents *events = [SCEvents sharedPathWatcher];
[events setDelegate:self];
NSMutableArray *paths = [NSMutableArray arrayWithObject:NSHomeDirectory()];
NSMutableArray *excludePaths = [NSMutableArray arrayWithObject:[NSHomeDirectory() stringByAppendingString:@"/Downloads"]];
[events setExcludedPaths:excludePaths];
[events startWatchingPaths:paths];
}
- (void)pathWatcher:(SCEvents *)pathWatcher eventOccurred:(SCEvent *)event
{
NSLog(@"%@", event);
}
我直接从 SCEvents 示例应用程序获取这些方法,一旦我让它工作,我计划根据自己的目的更改它)
主应用程序委托类的 applicationDidFinishLaunching 方法中,我有这个:
EventListener *events = [[EventListener alloc] init];
[events setupEventlistener];
然后在我的 听者。现在,在分配它并调用 setupEventListener 类之后,一切正常。主文件夹内的更改将按原样记录到调试器控制台中。我有另一种名为 format: 的方法,它运行一些 shell 脚本。问题是,当格式化方法运行时,事件侦听器停止工作。对主文件夹的任何更改都不会记录。此问题仅发生在 format: 方法中。对于所有其他方法,事件侦听器都可以正常工作。
我不确定问题是什么。谢谢
[Note: The title may be less than accurate, I didn't know how else to phrase it]
For some reason NSFileHandle's readInBackground didn't work so I resorted to SCEvents, a Cocoa wrapper around Mac OS X's FSEvents API. I have a separate class called "EventListener" that handles all the SCEvents stuff.
It has these methods:
- (void)setupEventlistener
{
SCEvents *events = [SCEvents sharedPathWatcher];
[events setDelegate:self];
NSMutableArray *paths = [NSMutableArray arrayWithObject:NSHomeDirectory()];
NSMutableArray *excludePaths = [NSMutableArray arrayWithObject:[NSHomeDirectory() stringByAppendingString:@"/Downloads"]];
[events setExcludedPaths:excludePaths];
[events startWatchingPaths:paths];
}
- (void)pathWatcher:(SCEvents *)pathWatcher eventOccurred:(SCEvent *)event
{
NSLog(@"%@", event);
}
( I got these methods directly from the SCEvents example app, once I get this to work I plan to change it for my own purposes )
Then in the applicationDidFinishLaunching method of my main app delegate class I have this:
EventListener *events = [[EventListener alloc] init];
[events setupEventlistener];
Which initializes the listener. Now, after allocing it and calling the setupEventListener class, everything works fine. Changes inside the home folder are logged into the debugger console as they should be. I have another method called format: that runs some shell scripts . The issue is, when the format method is running the event listener stops working. Any changes to the home folder are NOT logged. This problem only happens with the format: method. With all other methods the event listener works fine.
I'm not sure what the problem is. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有另一种名为 format: 的方法,它运行一些 shell 脚本。问题是,当格式化方法运行时,事件侦听器停止工作。对主文件夹的任何更改都不会被记录。
这可能也是
-readInBackgroundAndNotify:
不起作用的原因。具体来说,除非您让事件循环(通知所针对的线程的)运行,否则通知机制通常不起作用。在某些情况下,如果您阻塞的时间足够长,通知就会丢失。
I have another method called format: that runs some shell scripts. The issue is, when the format method is running the event listener stops working. Any changes to the home folder are NOT logged.
This was probably the same reason why
-readInBackgroundAndNotify:
didn't work, either.Specifically, notification mechanisms typically don't work unless you let the event loop (of the thread to which the notifications are targeted) run. In some cases, if you block long enough, notifications will be lost.