AVAudioEngine se bloquea cuando descojo los auriculares durante una llamada

Esto es lo que veo en el logging:

16:33:20.236: Call is Dialing 16:33:21.088: AVAudioSessionInterruptionNotification 16:33:21.450: AVAudioSessionRouteChangeNotification 16:33:21.450: ....change reason CategoryChange 16:33:21.539: AVAudioEngineConfigurationChangeNotification 16:33:21.542: Starting Audio Engine 16:33:23.863: AVAudioSessionRouteChangeNotification 16:33:23.863: ....change reason OldDeviceUnavailable 16:33:23.860 ERROR: [0x100a70000] AVAudioIONodeImpl.mm:317: ___ZN13AVAudioIOUnit11GetHWFormatEjPj_block_invoke: requinetworking condition is false: hwFormat *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'requinetworking condition is false: hwFormat' 

Me he suscrito para AVAudioEngineConfigurationChangeNotification , AVAudioSessionInterruptionNotification :

 @objc private func handleAudioEngineConfigurationChangeNotification(notification: NSNotification) { println2(notification.name) makeEngineConnections() startEngine() } @objc private func handleAudioSessionInterruptionNotification(notification: NSNotification) { println2(notification.name) if let interruptionType = AVAudioSessionInterruptionType(rawValue: notification.userInfo?[AVAudioSessionInterruptionTypeKey] as! UInt) { switch interruptionType { case .Began: audioPlayerNode.stop() case .Ended: if let interruptionOptionValue = notification.userInfo?[AVAudioSessionInterruptionOptionKey] as? UInt { let interruptionOption = AVAudioSessionInterruptionOptions(interruptionOptionValue) if interruptionOption == AVAudioSessionInterruptionOptions.OptionShouldResume { AVAudioSession.shanetworkingInstance().setActive(true, error: nil) startEngine() } } } } } func startEngine() { println2("Starting Audio Engine") var error: NSError? if !audioEngine.running { audioEngine.startAndReturnError(&error) if let error = error { println2("Error initializing Audio Engine: " + error.localizedDescription) } } } private func makeEngineConnections() { let mainMixer = audioEngine.mainMixerNode audioEngine.connect(audioPlayerNode, to: audioEqNode, format: mainMixer.outputFormatForBus(0)) audioEngine.connect(audioEqNode, to: audioTimePitch, format: mainMixer.outputFormatForBus(0)) audioEngine.connect(audioTimePitch, to: mainMixer, format: mainMixer.outputFormatForBus(0)) } 

pero no parece funcionar.

¿Cómo evitar este queuepso?

Sospecho que el problema está aquí:
audioEngine.connect(audioTimePitch, to: mainMixer, format: mainMixer.outputFormatForBus(0))

La documentation dice:

Este método llama connect: to: fromBus: toBus: format: usando el bus 0 para el nodo de audio de origen y el bus 0 para el nodo de audio de destino, excepto en el caso de un destino que sea un mezclador, en cuyo caso el destino es el NextBestInputBus de mezclador.