我正在编写一个与 USB HID 设备接口的 Mac 应用程序。首先,我试图打印出找到了多少与我的设备规格相匹配的设备。
//Create a HID Manager
IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
//Create a dictionary and limit it to the uPPT
CFMutableDictionaryRef dict = CFDictionaryCreateMutable (kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(dict, CFSTR("VendorID"), CFSTR("0x04D8"));
CFDictionarySetValue(dict, CFSTR("ProductID"), CFSTR("0x0054"));
IOHIDManagerSetDeviceMatching(hidManager, dict);
CFSetRef devSet = IOHIDManagerCopyDevices (hidManager);
CFIndex numDevices = CFSetGetCount(devSet);
NSLog(@"%ld uPPTs found", numDevices);
不幸的是,这在 CFSetGetCount(devSet) 处崩溃。据我所知,我使用正确,但应用程序挂起,我看到“线程 1:EXC_BAD_ACCESS(代码=1,地址=0x0)”。有任何想法吗?谢谢