2015-11-04 76 views
0

我想使用Xcode创建的应用程序观看mac OS X的下载目录。 下面是我用来记录正在移动的文件的代码。但是,当我转到我的文档并移动文件时,甚至不会调用委托方法。有没有适当的方式来做到这一点,我失踪了?IOS - 文件添加触发事件 - 是否有可能

- (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; 
} 
+1

iOS或OSX?目前尚不清楚。 http://stackoverflow.com/questions/1386743/observe-a-file-or-folder-in-objective-c? – Larme

回答

0

shouldMoveItemAtPath不监视文件更改。

您需要使用FSEvents来获取事件信号发送文件系统更改。

+0

这就是我所担心的,我还没有看到FSEvents的任何好的教程/例子。我会更深入地看,谢谢。 – CoderJ