【发布时间】:2019-05-10 23:08:31
【问题描述】:
从 stackfow 链接尝试了这个解决方案:
CFMutableDictionaryRef matchingDict = IOServiceMatching ( kIOUSBDeviceClassName );
if ( matchingDict )
{
UInt32 usbVendor = k_MyVendorID;
CFNumberRef refVendorId = CFNumberCreate ( kCFAllocatorDefault, kCFNumberIntType, &usbVendor );
CFDictionarySetValue ( matchingDict, CFSTR ( kUSBVendorID ), refVendorId );
CFRelease ( refVendorID );
CFDictionarySetValue ( matchingDict, CFSTR ( kUSBProductID ), CFSTR ( "*" ) ); // This is a wildcard, so we find any device.
}
在添加新设备时似乎工作:
kr = IOServiceAddMatchingNotification(gNotifyPort,kIOMatchedNotification, matchingDict, RawDeviceAdded, NULL, &gRawAddedIter);
有了这些,它要么崩溃,要么列表没有更新,删除设备似乎确实有效。 //终止通知:
kr = IOServiceAddMatchingNotification(gNotifyPort, kIOTerminatedNotification, matchingDict, RawDeviceRemoved, NULL, &gRawRemovedIter);
//终止通知:
kr = IOServiceAddMatchingNotification(gNotifyPort, kIOTerminatedNotification, matchingDict, NonRawDeviceRemoved, NULL, &gRawRemovedIter);
处理这个问题的最佳方法是什么?
【问题讨论】:
标签: macos cocoa usb foundation iokit