Hi all, I'm trying to write a little utility app that can detect when my bluetooth mouse is connected and turn natural scrolling off. I started by creating a Swift Package with swift package init --type excecutable and then wrote the following code in main.swift:
import CoreHID
let manager = HIDDeviceManager()
let notifications = await manager.monitorNotifications(
matchingCriteria: [.init(primaryUsage: .genericDesktop(.mouse))]
)
for try await notification in notifications {
switch notification {
case .deviceMatched(let device):
print("Matched:", device.deviceID)
let client = HIDDeviceClient(deviceReference: device)
print(await client?.manufacturer ?? "Unknown")
case .deviceRemoved(let device):
print("Removed:", device.description)
let client = HIDDeviceClient(deviceReference: device)
print(await client?.manufacturer ?? "Unknown")
@unknown default:
print("Unknown: \(notification)")
}
}
This program successfully detects my bluetooth mouse and correctly prints "Logitech", but when it gets to a second device, it crashes with the error message I put in the title: EXC_BREAKPOINT (code=1, subcode=0x1f9e0e13c).
If I run the program without my bluetooth mouse connected, it just crashes immediately so I can only assume this second device is the trackpad.
I added some log statements in addition to the prints so I could check unified logging in Console but nothing really stood out. No code signing errors, no permission denials, nada.
My environment:
MacBook Air 13-inch, M3, 2024
MacOS 15.1 (24B83)
Xcode Version 16.0 (16A242d)
swift-tools-version: 6.0
$ swift --version
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Has anyone seen this before or have ideas on how to investigate further?
Topic:
App & System Services
SubTopic:
Core OS