USBDeviceSwift icon indicating copy to clipboard operation
USBDeviceSwift copied to clipboard

Receive disconnect notification but not "connected"

Open nicholasamorim opened this issue 6 years ago • 9 comments

Hi, can you think of any reason why I can receive the disconnection notification but not the connected notification?

There's no errors whatsoever, I simply don't get the connected notification. I've tried a few different usb devices and all the same.

Using Swift 4 in High Sierra.

nicholasamorim avatar Aug 31 '18 14:08 nicholasamorim

I've dug into the code and noticed the problem lies in here:

// USB device object is no longer needed.
IOObjectRelease(usbDevice)

// Dereference pointer for the plug-in interface
if (kr != kIOReturnSuccess) {
    continue
}

It hits that continue and never posts the notification. If I comment that continue out, to see what happens, this happens:

Unable to get Plug-In Interface

nicholasamorim avatar Aug 31 '18 14:08 nicholasamorim

So, upon further investigation, it stops working on 10.13 deployment target.

Works fine if I use older versions, though.

nicholasamorim avatar Aug 31 '18 14:08 nicholasamorim

@nicholasamorim Reviving an old thread, but did you find a fix for this ?

fdidron avatar Sep 27 '19 03:09 fdidron

@nicholasamorim Nevermind i found the answer after some serious head scratching. On Xcode 11, I had to tick the USB option on in the Project file > Targets > {APP NAME} > Sigining & Capabilities > App Sandbox

fdidron avatar Sep 27 '19 04:09 fdidron

@fdidron it took you a year to respond to the first poster and now a year later, I am thanking you for your comment :)

sbilstein avatar Aug 19 '20 17:08 sbilstein

@nicholasamorim Nevermind i found the answer after some serious head scratching. On Xcode 11, I had to tick the USB option on in the Project file > Targets > {APP NAME} > Sigining & Capabilities > App Sandbox

This should be added somewhere in the docs!

txbrown avatar Nov 09 '20 00:11 txbrown

@fdidron so many thanks!

txbrown avatar Nov 09 '20 00:11 txbrown

@sbilstein @txbrown monthes later I'm back at it and I'm running into the following issue on a M1 Mac. As soon as I add the App Sandbox entitlement to my application and run it, it crashes

Thread 1: EXC_BREAKPOINT (code=1, subcode=0x192b73110) in libsystem_secinit.dylib`_libsecinit_appsandbox.cold.5:

fdidron avatar Dec 10 '20 02:12 fdidron

@fdidron hey sorry for the much late reply. I realised for me was easier to wrap libusb in a swift module and use that. took me way less time than fighting to understand this library without docs.

txbrown avatar Jan 11 '21 23:01 txbrown