Hi, I tried it and I got the context below when initializing.
Change
New devices: [ .... ]
When I disconnect AirPods, the log Output won't be shown anymore but I got nothing more.
When I disconnect the AirPods, it was not shown on Settings app.
I tried this code
for i in 0..<60 {
sleep(1)
for device in discovery_session.devices {
print(device.localizedName)
}
}
session.stopRunning()
Then it seems that the devices list is not updated. This code prints the same content every time while the app is runnning.
I don't have EarPods now, so I will try it later.
Post
Replies
Boosts
Views
Activity
Hello, @Engineer, thank you for your reply.
I still cannot receive any notification using this code on macOS with AirPods or EarPods.
NotificationCenter.default.addObserver(forName: AVCaptureDevice.wasDisconnectedNotification, object: nil, queue: nil) { notification in
print("disconnected \(notification)")
}
I found a similar issue on StackOverflow.
https://stackoverflow.com/questions/30789622/avcapturedevice-deviceswithmediatype-does-not-update-after-added-removed-camera
I tried the soluon( use AVCaptureDevice.devices() instead of AVCaptureDevice.DiscoverySession.devices() ) in the page, but it doesn't work.
I forgot to say, the target OS is macOS.
Could anyone write a sample Swift code to detect a microphone disconnect using AVCapture for macOS?
Is there someone who can run my example to detect device changes?
Or this is a bug?