jww
jww

Reputation: 102376

iPhone/iPad: Directory Change Notification

I have an application with UIFileSharingEnabled. If the device is tethered, a user can use iTunes (or other programs) to drop new files or delete existing files. I would like to detect the changes to my application's file system on the device.

Is there a 'directory change' (or similar) notification? Notification Programming Topics does not appear to have a comprehensive list of notifications.

I believe Galea's answer (below) would probably work, but GCD is only available in iOS 4.0 and later. Unfortunately, I'm targeting iOS 3.2.

Upvotes: 1

Views: 1010

Answers (2)

Giuliano Galea
Giuliano Galea

Reputation: 982

You can use Grand Central Dispatch, in particular dispatch_source_create can be a good start. (by the way GCD is built on top of kqueue, at least for what concerns the event part)

Upvotes: 1

Abhi Beckert
Abhi Beckert

Reputation: 33369

Yes, it's a UNIX system! You can use the kqueue() feature to monitor directory changes as they happen.

Here's an example of how to use it: http://blog.julipedia.org/2004/10/example-of-kqueue.html. Or if you prefer, there's a nice Objective-C wrapper class call UKKQueue: http://www.zathras.de/angelweb/sourcecode.htm

I believe he event will be fired when the new files are created, not when the write operation is finished. So you will not be able to read the files immediately - but displaying the file in a list should be fine.

If you need to read the file (maybe to display a preview of a jpeg for example), you could just wait a few seconds after it's been copied using NSTimer.

Upvotes: 0

Related Questions