AAUSBAccessoryManager does not fire didconnect

Hi, I am trying to use AAUSBAccessoryManager with mac os 27 to connect host usb device to guest vm.

here is my code

//
//  USBPassthroughManager.swift
//  VirtualProg

import AccessoryAccess
import Foundation
import IOKit

@available(macOS 27.0, *)
class USBPassthroughManager: NSObject, ObservableObject, AAUSBAccessoryListener {
    static let shared = USBPassthroughManager()

    @Published var availableDevices: [AAUSBAccessory] = []

    func startListening() async {
        do {
            let existing = try await AAUSBAccessoryManager.shared
                .registerListener(self, matchingCriteria: [])
            await MainActor.run {
                self.availableDevices = existing
            }
        } catch {
            LogManager.shared.log(vmName: AppConstants.logGeneral, type: .error,
                                  message: "USB passthrough listener failed: \(error.localizedDescription)")
        }
    }

    func usbAccessoryDidConnect(_ usbAccessory: AAUSBAccessory) {
        DispatchQueue.main.async {
            guard !self.availableDevices.contains(where: { $0.registryID == usbAccessory.registryID }) else { return }
            self.availableDevices.append(usbAccessory)
            print(self.displayName(for: usbAccessory))
        }
    }

The usb icon in status bar menu is displayed and i can select the the usb device to connect to my app. the usb device is connected to my app. it is shown in the status bar.

but usbAccessoryDidConnect is not firing.

i have the entitlement com.apple.developer.accessory-access.usb in the capabilities.

i get this in the xcode console

start failed ((iokit/common) not permitted) for plugin for ..........

and also disconnect is also not firing. Not sure what i am doing wrong.

How can i determine the name of the USB Device from AAUSBAccessory.

Any help would be appreciated.

Thanks

Answered by DTS Engineer in 904152022

You’re using the wrong entitlement [1]. Consider this test app, where I added the Claim USB Accessory capability:

% codesign -d --entitlements - Test831902.app 
…
[Dict]
    …
    [Key] com.apple.developer.accessory-access.usb
    [Value]
        [Bool] true
    …

IMPORTANT This is a restricted entitlement, which means it must be authorised by a provisioning profile. There’s no good way to associate a provisioning profile with a command-line tool. You have to embed it in an app-like wrapper. See Signing a daemon with a restricted entitlement.

Is AccessoryAccess even supported for CLI-tools … ?

Successfully the correct entitlement will get you past the first hurdle, but they may be others. This API was definitely created with apps in mind.

Share and Enjoy

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

[1] com.apple.security.device.usb is an App Sandbox entitlement.

Accepted Answer

Got it we need to enable com.apple.security.device.usb in the capabilities also. It is working fine as expected.

I tried connecting an iPhone, HD Web Cam , Mic to guest vm and it failed. connecting usb drives worked fine without any problem. Is there a list of devices that is supported?

Is there a list of devices that is supported?

No.

If you encounter a problem like this, I recommend that you file a bug about it. And please post your bug number, just for the record.

Oh, and it might make sense to file multiple bugs for different groups of device types. For example, media devices, like microphones and cameras, are very different from iOS devices, like your iPhone.

Share and Enjoy

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

here is the bug number FB23222154

Thanks.

You didn’t include a sysdiagnose with that bug, so it’s on its way back to you asking for that. Our bugs folks will be in touch about that at some point, but if you want to add it now then that’ll speed things up.

Make sure to take the sysdiagnose shortly after reproducing the problem, and also add info that:

  • Makes it clear which accessory you tried to capture.
  • Describes the timeline of the failure, that is, roughly when you made this attempt.

Share and Enjoy

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

Make sure to take the sysdiagnose shortly after reproducing the problem, and also add info that:

  • Makes it clear which accessory you tried to capture.
  • Describes the timeline of the failure, that is, roughly when you made this attempt.

I added a reply to FB witht the details you have asked for. thanks

Quick question about AccessoryAccess on macOS 27:

I’m trying to use it from a CLI tool (packaged as a minimal .app bundle, signed with com.apple.security.device.usb), but I keep getting:

Internal AccessoryAccess error. Unable to communicate with service.

From the WWDC26 session it sounds like just adding the entitlement isn’t enough and the corresponding capability in “Signing & Capabilities” needs to be enabled.

Is AccessoryAccess even supported for CLI-tools, or does it require a full app target?

You’re using the wrong entitlement [1]. Consider this test app, where I added the Claim USB Accessory capability:

% codesign -d --entitlements - Test831902.app 
…
[Dict]
    …
    [Key] com.apple.developer.accessory-access.usb
    [Value]
        [Bool] true
    …

IMPORTANT This is a restricted entitlement, which means it must be authorised by a provisioning profile. There’s no good way to associate a provisioning profile with a command-line tool. You have to embed it in an app-like wrapper. See Signing a daemon with a restricted entitlement.

Is AccessoryAccess even supported for CLI-tools … ?

Successfully the correct entitlement will get you past the first hurdle, but they may be others. This API was definitely created with apps in mind.

Share and Enjoy

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

[1] com.apple.security.device.usb is an App Sandbox entitlement.

AAUSBAccessoryManager does not fire didconnect
 
 
Q