Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Hi all,

I'm trying to make a little application, which partly needs to be able to 'monitor' the USB interfaces.
No communication or other, just only monitor if something is connected, and disconnected.

I ended up with this:
Code:
IOHIDManagerRef HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeSeizeDevice);
    IOHIDManagerSetDeviceMatching(HIDManager, NULL);
   
    IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, &Handle_DeviceMatchingCallback, NULL);
    IOHIDManagerRegisterDeviceRemovalCallback(HIDManager, &Handle_DeviceRemovalCallback, NULL);
   
    IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
   
    IOReturn IOReturn = IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone);
    if(IOReturn) puts("IOHIDManagerOpen failed.");

This is working, except for iDevices (iPhones etc.)
I have also tried other examples using filters based on vendor id etc. but still iPhones etc are not being detected.

Does anyone have an idea ?
 
I found other sample in swift, which takes vendor and product id.
When I enter both and for example 0x12a8 (out of my head I found it on google first result on “usb product id iphone”)
Then it works, but obviously iphones, ipads, ipods, apple tv’s and watches have different product ids. I don’t want to update the script every time when there is a new idevice.

I just simply want to have a small hook for: ANY usb change
No matter what vendor or product it is.
That will already help me out a lot here.

I have a lot of help of Apple's USBPrivateDataSample :)
It's working now :)
Anyone interested in this part, just reply
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.