I am listening to NSWorkspaceDidMountNotification and NSWorkspaceDidUnmountNotification for the USB device mount and unmount notifications.
That's not what those notifications are for. They are volume mount and unmount notifications, and a volume can come from something that isn't a USB device. Disk images, FireWire devices, optical discs, and flash memory cards are all devices that are not USB devices. (The card may be in a USB card reader, but the card is not the reader.)
I think the way forward is IOKit.
Correct.
But I have a feeling that it for low level programming.
Correct.
Is there any other way to find these?
You can't cut out I/O Kit completely, but there is a shortcut that may save you some work. It's the Disk Arbitration framework.
Register a disk-appeared callback and a disk-disappeared callback. Each callback function, which you implement, takes a DADiskRef
. You can pass this to the DADiskCopyIOMedia
function to get a service port to the I/O Kit media object for the disk.
I have no idea of what to do then, except that you will need to release the service port as described in that documentation. Also, you will still need to filter out non-USB devices, but at least you'll have the I/O Kit media object to do it with.
One other thing: This solution, and the NSWorkspace notifications you're currently using, probably both will not work if the iPod is not set to use, or does not support, disk mode. iPhones and iPods touch are the biggest current example. If that's the case, then you are just going to have to use I/O Kit from start to finish—neither DiskArb nor NSWorkspace will do the job for you.