Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do NSFilePresenter protocol methods never get called?

I am trying to monitor file changes in local and iCloud directories and have implemented the NSFilePresenter protocol methods but the only method that gets called is presentedItemAtURL.

Am I correct in assuming that I should be able to monitor a local or an iCloud directory and get notified any time any process adds, modifies or deletes a file in the directory.

Here is the basic code for the OS X App:

- (void)awakeFromNib {
        _presentedItemURL = myDocumentsDirectoryURL;
        _presentedItemOperationQueue = [[NSOperationQueue alloc] init];
        [_presentedItemOperationQueue setMaxConcurrentOperationCount: 1];
        _fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:self];
}
- (NSURL*) presentedItemURL {
    FLOG(@" called %@", _presentedItemURL);
    return _presentedItemURL;
}

- (NSOperationQueue*) presentedItemOperationQueue {
    FLOG(@" called");
    return _presentedItemOperationQueue;
}

- (void)presentedItemDidChange {
    FLOG(@" called");
    dispatch_async(dispatch_get_main_queue(), ^{
        [self reloadData];
    });
}
-(void)accommodatePresentedItemDeletionWithCompletionHandler:(void (^)(NSError *errorOrNil))completionHandler
{   FLOG(@" called");
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self reloadData];
    }];
    completionHandler(nil);
}
-(void)presentedSubitemDidChangeAtURL:(NSURL *)url {
    FLOG(@" called");
    dispatch_async(dispatch_get_main_queue(), ^{
        [self reloadData];
    });
}
-(void)presentedSubitemDidAppearAtURL:(NSURL *)url {
    FLOG(@" called");
    dispatch_async(dispatch_get_main_queue(), ^{
        [self reloadData];
    });

}
like image 609
Duncan Groenewald Avatar asked Oct 01 '22 10:10

Duncan Groenewald


1 Answers

Long time ago, I know, but perhaps this will still help. NSFilePresenter will only notify you about changes made by another process that makes changes to a directory or file USING AN NSFileCoordinator. If another process (eg: iTunes file sharing) makes changes without an NSFileCoordinator, you won't be notified.

like image 156
Christopher Schardt Avatar answered Oct 13 '22 12:10

Christopher Schardt