IOUSBHostDevice: Exclusive open of usb object failed

I have a command line tool and am trying to connect to a USB device using:
Code Block Objective-C
   _device = [[IOUSBHostDevice alloc] initWithIOService:_service
   options:IOUSBHostObjectInitOptionsDeviceCapture
   queue:_queue
   error:&error
   interestHandler:^(IOUSBHostObject * _Nonnull hostObject, uint32_t messageType, void * _Nullable messageArgument) {
    NSLog(@"Interest handler...");
   }];


However, when I run this tool (even under sudo), I'm hitting the error:

Error:Unable to open io_service_t object and create user client. with reason: Exclusive open of usb object failed.

The documentation for IOUSBHostObjectInitOptionsDeviceCapture implies that using this option and having root privilege should gain exclusive access to the device. The alternative is to use an entitlement, but the executable is terminated immediately in that case probably due to code signing.

I would have expected that running the tool under sudo would have been sufficient to avoid this issue.

I just want to first get things working locally on my Mac for a proof of concept, so I don't really want to deal with code signing up front unless that is absolutely necessary.

What do I need to do to get exclusive access to the USB device?

Thanks in advance.


Replies

I am facing this issue too for a while and can't figure it out. Any pointers here?

Hi, is this problem resolved? I am also facing the same issue, after add "com.apple.vm.device-access" entitlement, click run my sandbox app, it crashed

it crashed

See my response on the other thread here you raised this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"