I'm having big troubles using FSEventStream in my XPC service (code below). Service starts, stream is created, but callback function is never called. When I copy exactly the same code to my main application and run it, it works just fine. What may be the reason that it doesn't work in XPC service? I've tried to disable AppSandbox in both parts, but it didn't change anything. Any help with this is highly appreciated.
code:
- (void)initEventNotificationStreamForPath:(NSString *)path {
NPDLOG(@"Starting up FS event listener for path: %@", path);
NSArray *pathsToWatch = @[path];
FSEventStreamContext context;
context.info = (__bridge void *)self;
context.version = 0;
context.retain = NULL;
context.release = NULL;
context.copyDescription = NULL;
NSTimeInterval latency = 1.0;
_eventStream = FSEventStreamCreate(NULL, &eventNotificationCallback, &context, (__bridge CFArrayRef)pathsToWatch, kFSEventStreamEventIdSinceNow, //[lastEventID unsignedLongLongValue],
(CFAbsoluteTime)latency, (kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagFileEvents | kFSEventStreamCreateFlagWatchRoot));
if(_eventStream) {
NPDLOG(@"Scheduling event stream on runloop");
FSEventStreamScheduleWithRunLoop(_eventStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
if(!FSEventStreamStart(_eventStream)) {
NPDLOG(@"Could NOT start event stream listener!!!");
}
else {
CFStringRef description = FSEventStreamCopyDescription(_eventStream);
NPDLOG(@"Stream description: %@", description);
CFRelease(description);
}
}
else {
NPDLOG(@"Could NOT create event stream listener!!!");
}
}
My callback function:
void eventNotificationCallback(ConstFSEventStreamRef streamRef, void *userData, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) {
//[((__bridge NPScannerServiceAgent *)userData).remoteObject didUpdateFilesAtPaths:(__bridge NSArray *)eventPaths];
printf("CALLBACK CALLED!!!\n");
NSLog(@"GOT FS CHANGE NOTIFICATION FROM %@", (__bridge NPScannerServiceAgent *)userData);
size_t i;
for(i = 0; i < numEvents; i++) {
NSLog(@"Modified path: %@, flags: %d", [(__bridge NSArray *)eventPaths objectAtIndex: i], eventFlags[i]);
}
}