简体   繁体   中英

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. 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.

You need to use FSEvents to get events signalling file system changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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