Hi all, Can't get a simple example working. AppearedNotificationHandler() should be called in the code below when a USB device (any device for now) is plugged in. I see the NSLog(@"registerDeviceCallbackHandler") message appear in the console when I start the application, but never see the NSLog(@"AppearedNotificationHandler") message when I plug in a device. What am I missing?
Note: The project's MainMenu.nib Interface Builder file has an NSObject whose class is "USBDriver". static void AppearedNotificationHandler (void * refCon, io_iterator_t iterator); @interface USBDriver(Private) - (void) registerDeviceCallbackHandler; @end @implementation USBDriver(Private) - (void) registerDeviceCallbackHandler { IOReturn kernErr; CFRunLoopSourceRef runLoopSource; CFMutableDictionaryRef matchingDict = IOServiceMatching (kIOUSBDeviceClassName); CFRunLoopRef runLoop; // Create the port on which we will receive notifications. We'll wrap it in a runLoopSource // which we then feed into the runLoop for async event notifications. deviceNotifyPort = IONotificationPortCreate (kIOMasterPortDefault); if (deviceNotifyPort == NULL) { return; } // Get a runLoopSource for our mach port. runLoopSource = IONotificationPortGetRunLoopSource (deviceNotifyPort); matchingDict = (CFMutableDictionaryRef) CFRetain (matchingDict); kernErr = IOServiceAddMatchingNotification (deviceNotifyPort, kIOFirstMatchNotification, matchingDict, AppearedNotificationHandler, (void *) self, &deviceAppearedIterator); kernErr = IOServiceAddMatchingNotification (deviceNotifyPort, kIOTerminatedNotification, matchingDict, DisappearedNotificationHandler, (void *) self, &deviceDisappearedIterator ); // Get our runLoop runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop]; // Add our runLoopSource to our runLoop CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopDefaultMode); NSLog(@"registerDeviceCallbackHandler"); } @end @implementation USBDriver - (id) init { [super init]; if (self) { deviceNotifyPort = IO_OBJECT_NULL; deviceAppearedIterator = 0; [self registerDeviceCallbackHandler]; } return self; } @end static void AppearedNotificationHandler (void * refCon, io_iterator_t iterator) { NSLog(@"AppearedNotificationHandler"); } Any help is much appreciated. Thanks, Chris _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com