I listen to NSWorkspaceDidMountNotification and NSWorkspaceDidUnmountNotification to connect devices to a USB device and unmount notifications.
This is not what these notifications are for. They are notifications of volume installation and shutdown, and the volume may come from the fact that it is not a USB device. Disk images, FireWire devices, optical disks, 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 a reader.)
I think the way forward is IOKit.
Right.
But I feel this is for low level programming.
Right.
Is there any other way to find them?
You cannot completely cut the I / O set, but there is a shortcut that can save you some work. This is the structure of disk arbitration.
Register callback with disk and disk disappeared Callback . Each callback function that you implement takes a DADiskRef . You can pass this function to DADiskCopyIOMedia to get the service port for the Kit I / O media object for the disk.
I have no idea what to do except that you will need to release a service port, as described in this documentation. In addition, you will still have to filter out non-USB devices, but at least you will have an I / O Kit media object for this.
One more thing: this solution and the NSWorkspace notifications you are currently using will probably not work if the iPod is not configured to use or does not support disk mode. The touch of the iPhone and iPod is the biggest example. In this case, you just have to use the I / O set from start to finish - neither DiskArb nor NSWorkspace will do the job for you.
source share