如何在Mac OS可可中获取已安装的USB设备的设备ID,供应商ID和产品ID [英] how to get Device id, vendor id and product id of a mounted usb device in Mac OS cocoa

查看:1056
本文介绍了如何在Mac OS可可中获取已安装的USB设备的设备ID,供应商ID和产品ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个Cocoa程序,检测iPod连接到Mac OS。我正在侦听NSWorkspaceDidMountNotification和NSWorkspaceDidUnmountNotification用于USB设备装载和卸载通知。我可以得到装载设备的路径使用NSString * path = [[notif userInfo] objectForKey:@NSDevicePath];但我还需要知道设备ID,供应商Id,产品Id等,以检查安装的设备是否是一个iPod。我认为前进的道路是IOKit。但我有一种感觉,它为低级编程。有没有其他方法来找到这些?此外,如果是IO套件,是否有任何示例程序,当我提供装载路径时将提供Id?



非常感谢。



我正在侦听NSWorkspaceDidMountNotification和NSWorkspaceDidUnmountNotification用于USB设备装载和卸载通知。 blockquote>

这不是那些通知。它们是安装和卸载通知,并且卷可以来自不是USB设备的东西。磁盘映像,FireWire设备,光盘和闪存卡都是不是USB设备的设备。 (该卡可能在USB读卡器中,但该卡不是读卡器。)


我认为前进的道路是IOKit。


正确。


对于低级编程的感觉。


正确。


有没有其他方法可以找到这些?


但有一个快捷方式,可以救你一些工作。它是磁盘仲裁框架。



注册磁盘出现的回调磁盘消失的回调。每个回调函数,你实现,需要一个 DADiskRef 。您可以将此传递给 DADiskCopyIOMedia 函数,以获取磁盘的I / O Kit介质对象的服务端口。



我不知道该做什么,除了你需要释放服务端口,如该文档中所述。此外,您仍然需要过滤掉非USB设备,但至少您将有I / O Kit媒体对象来完成。



另一个事情:这个解决方案,和你当前使用的NSWorkspace通知,如果iPod不设置为使用或不支持磁盘模式,可能都不工作。 iPhone和iPod touch是当前最大的例子。如果是这样,那么你只需要从头到尾使用I / O Kit,DiskArb和NSWorkspace都不会为你完成这项工作。


I am trying to write a Cocoa program which detects iPods connected to Mac OS. I am listening to NSWorkspaceDidMountNotification and NSWorkspaceDidUnmountNotification for the USB device mount and unmount notifications. I can get the device path of the mounted device using NSString *path = [[notif userInfo] objectForKey:@"NSDevicePath"]; but I also need t know the Device Id, Vendor Id, Product Id etc to check whether the mounted device is an iPod. I think the way forward is IOKit. But I have a feeling that it for low level programming. Is there any other way to find these? Also, if it is IO kit is there any sample program which will give the Ids when I provide mount path?

Thanks a lot.

解决方案

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.

这篇关于如何在Mac OS可可中获取已安装的USB设备的设备ID,供应商ID和产品ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆