我正在尝试监视本地和 iCloud 目录中的文件更改,并实现了 NSFilePresenter 协议方法,但唯一被调用的方法是presentedItemAtURL
.
我是否正确假设我应该能够监视本地或 iCloud 目录并在任何进程添加、修改或删除目录中的文件时收到通知。
这是 OS X 应用程序的基本代码:
- (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];
});
}