Skip navigation.
 
mlIOServiceAddMatchingNotification
FROM : Greg Hoover
DATE : Tue Jan 22 17:53:25 2008

I'm using the following code to add a notification callback for HID 
devices.  It works the first time I plug in the USB device (and 
sometimes the 2nd time), but typically only the first plug in is ever 
registered.  My understanding is that the notification is persistent 
and shouldn't need to be recreated, no?

Thanks in advance.

+ (void)addHIDDeviceAddedNotificationCallback:
(IOServiceMatchingCallback)notificationCallback withContext:(void 
*)context {
    NSMutableDictionary     *matchingDict;
    kern_return_t            result;
   io_iterator_t            addedIterator;
   
   if (!notifyPort)
       notifyPort = IONotificationPortCreate(kIOMasterPortDefault);
    CFRunLoopAddSource(CFRunLoopGetCurrent(),
                        IONotificationPortGetRunLoopSource(notifyPort),
                        kCFRunLoopDefaultMode);

    matchingDict = (NSMutableDictionary 
*)IOServiceMatching(kIOHIDDeviceKey);
    if (!matchingDict)
       return;

    result = IOServiceAddMatchingNotification(notifyPort,    
                                             kIOFirstMatchNotification,
                                             (CFMutableDictionaryRef)matchingDict,            
                                             notificationCallback,        
                                             context,            
                                             &addedIterator);

   // have to call to arm the notification callback
   while (IOIteratorNext(addedIterator));
}

Related mailsAuthorDate
No related mails found.