【问题标题】:Mac OS X Notification with same Vendor ID and different Product IDs具有相同供应商 ID 和不同产品 ID 的 Mac OS X 通知
【发布时间】: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


    【解决方案1】:

    您是否尝试在两次调用IOServiceAddMatchingNotification 时重复使用相同的matchingDictIOServiceAddMatchingNotification等函数都会释放传入的匹配字典,所以如果要使用两次,必须CFRetain(matchingDict);一次才能开始使用。

    (构建 -> 分析理论上应该会为您捕获此错误。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 2021-07-11
      • 1970-01-01
      相关资源
      最近更新 更多