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
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.