2

I am currently monitoring multiple file paths from an array with objective-c by using this function:

-(void)monitorPath:(NSString*)path{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    int fildes = open([path UTF8String], O_EVTONLY);

    __block typeof(self) blockSelf = self;
    __block dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fildes,
                                                              DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_RENAME, queue);
    dispatch_source_set_event_handler(source, ^{
        unsigned long flags = dispatch_source_get_data(source);
            NSLog(@"Path altered");
    });
    dispatch_source_set_cancel_handler(source, ^(void) {
        close(fildes);
    });
    dispatch_resume(source);
}

Is there a method to stop all of the file paths from being monitored?

maxisme
  • 3,974
  • 9
  • 47
  • 97
  • call "`dispatch_source_set_cancel_handler`" ? – Michael Dautermann Oct 15 '15 at 21:17
  • And that would kill all the process? – maxisme Oct 15 '15 at 21:19
  • For anyone else looking at this question, [it looks like Maximillian got his code from this related question](http://stackoverflow.com/questions/12343833/cocoa-monitor-a-file-for-modifications) and [blog post](http://www.davidhamrick.com/2011/10/13/Monitoring-Files-With-GCD-Being-Edited-With-A-Text-Editor.html). Too bad there isn't more context in there to work with. – Michael Dautermann Oct 16 '15 at 12:05

0 Answers0