How to get device ID, seller ID and product ID of installed USB device in Mac OS cocoa

I am trying to write a Cocoa program that detects iPods connected to Mac OS. I listen to NSWorkspaceDidMountNotification and NSWorkspaceDidUnmountNotification to connect and disconnect USB devices. I can get the device device path of the connected device using NSString * path = [[notif userInfo] objectForKey: @ "NSDevicePath"]; but I also need to know the device ID, seller ID, product ID, etc., to check if the installed iPod device. I think the way forward is IOKit. But I feel this is for low level programming. Is there any other way to find them? Also, if it is an IO set, is there any sample program that will give identifiers when I put the mount path?

Thank you very much.

+3
source share
3 answers

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.

+2
source

There's also Apple's HIDUtilites sample. Read the headers - as long as there is no excellent documentation for this structure, I think there is an example application or something with it.

0
source

you can use usbprobe, ioregistryexplorer or if you just want idProduct and ... u can always connect it to linux machine and use "lsusb -v" to get device information very reasonably, unlike ioregistryexplorer which seems to constantly break with every release of os x.

ioregistryexplorer also requires 100% membership in the program for Mac developers, like a mountain lion

0
source

All Articles