有几个使用FSEvent来侦听文件系统中的更改的示例。在FSEventStreamCreate中声明回调函数
How to listen for file system changes MAC - kFSEventStreamCreateFlagWatchRoot
和
FSEvents weirdness on OS X Leopard
当FSEventStreamCreate
创建活动,他们似乎都经过回调项就好了。没有参数或任何东西,只是&feCallback
。基本上看起来好像他们传递了一个变量而不是一个函数,如果这是有道理的话。
但是,当我尝试这样做时,出现Use of Undeclared identifier
错误。是什么赋予了?
FSEventStreamRef stream = FSEventStreamCreate(NULL,
&feCallback, // what does '&' mean? Why are no parameters passed?
&cntxt,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
1,
kFSEventStreamCreateFlagWatchRoot);
,再后来有回调函数:
static void feCallback(ConstFSEventStreamRef streamRef,
void* pClientCallBackInfo,
size_t numEvents,
void* pEventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
NSLog(@"The file changed!");
}
我喜欢一些示例代码在这里得到开源辅助对象的工作:https://bitbucket.org/boredzo/fs-notifier/overview
但同样的事情。它具有方法:
- (id) initWithCallback:(FSEventStreamCallback)newCallback path:(NSString *)newPath;
,我不能将它传递一个newCallback
因为上述错误的。
呵呵。我从来没有想到,简单地重新排序实际功能会使这项工作成为可能。我认为我需要以某种方式“创建”这个功能,我显然遇到了麻烦。如果你在'FSEventStreamCreate'的方法上面写了'static void feCallback'位,那么一切正常。猜猜这是一个来自Java/C#背景(所有这些都是自动完成的)的地方,对于Obj-C来说有点痛苦。 :) 谢谢您的帮助。 – cksubs