简体   繁体   English

iOS-文件添加触发事件-有可能吗

[英]IOS - File Added Trigger Event - Is it possible

I am trying to watch the downloads directory of a mac OS X using an Xcode created application. 我正在尝试使用Xcode创建的应用程序查看mac OS X的下载目录。 Below is the code used for my attempt at logging a file being moved. 以下是用于我尝试记录正在移动的文件的代码。 However when I goto my documents and move a file, the delegate method is not even called. 但是,当我转到文档并移动文件时,甚至没有调用委托方法。 Is there a proper way to do this that I am missing? 有没有合适的方法来做到这一点,我却不知道呢?

- (void)viewDidLoad {
    [super viewDidLoad];
    NSFileManager *manager = [[NSFileManager alloc] init];    // Do any additional setup after loading the view.
    [manager setDelegate:self];


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder

    [manager changeCurrentDirectoryPath:documentsDirectory];
}

- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath{
    NSLog(@"Attempt to move");
    return YES;
}

shouldMoveItemAtPath does not monitor file changes. shouldMoveItemAtPath不监视文件更改。

You need to use FSEvents to get events signalling file system changes. 您需要使用FSEvents来获取表示文件系统更改的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM