我正在尝试使用 FSEventStreamCreate 监听文件更改 - 虽然没有调用回调。以下是代码,应该按原样工作,但是?
提前致谢
#import "FileChangeController.h"
#include <CoreServices/CoreServices.h>
@implementation FileChangeController
- (id) init{
self = [super init];
if (self != nil) {
// fm = [NSFileManager defaultManager];
// images = [NSMutableArray new];
[self initializeEventStream];
}
return self;
}
- (void) awakeFromNib{
}
void fsevents_callback(ConstFSEventStreamRef streamRef,
void *userData,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
//FileChangeController *ac = (__bridge FileChangeController *)userData;
NSLog(@"Test");
size_t i;
for(i=0; i<numEvents; i++){
//[ac addModifiedImagesAtPath:[(NSArray *)eventPaths objectAtIndex:i]];
//[ac updateLastEventId:eventIds[i]];
}
}
- (void) initializeEventStream
{
NSString *myPath = @"/Users/NameOfUser/Desktop/Untitled.js"; //NSHomeDirectory();
NSArray *pathsToWatch = [NSArray arrayWithObject:myPath];
void *appPointer = (__bridge void *)self;
FSEventStreamContext context = {0, appPointer, NULL, NULL, NULL};
NSTimeInterval latency = 3.0;
stream = FSEventStreamCreate(NULL,
&fsevents_callback,
&context,
(__bridge CFArrayRef) pathsToWatch,
kFSEventStreamEventIdSinceNow, //[lastEventId unsignedLongLongValue],
(CFAbsoluteTime) latency,
kFSEventStreamCreateFlagUseCFTypes
);
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
FSEventStreamStart(stream);
}
@end