AVAudioRoutingArbiter
An object for configuring macOS apps to participate in AirPods Automatic Switching.
Declaration
class AVAudioRoutingArbiterOverview
AirPods Automatic Switching is a feature of Apple operating systems that intelligently connects wireless headphones to the most appropriate audio device in a multidevice environment. For example, if a user plays a movie on iPad, and then locks the device and starts playing music on iPhone, the system automatically switches the source audio device from iPad to iPhone.
iOS apps automatically participate in AirPods Automatic Switching. To enable your macOS app to participate in this behavior, use AVAudioRoutingArbiter to indicate when your app starts and finishes playing or recording audio. For example, a Voice over IP (VoIP) app might request arbitration before starting a call, and when the arbitration completes, begin the VoIP session. Likewise, when the call ends, the app would end the VoIP session and leave arbitration.
func startCall() {
let arbiter = AVAudioRoutingArbiter.shared
arbiter.begin(category: .playAndRecordVoice) { deviceChanged, error in
// Start VoIP session.
}
}
func endCall() {
// End VoIP session.
AVAudioRoutingArbiter.shared.leave()
}