From 4781ad983530493ee13069fd69ef9f15d154a3cc Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Fri, 14 Oct 2022 12:30:22 +0200 Subject: [PATCH] feat: Continue to record audio when receiving a phone call (try to prevent interruptions) (#1278) * feat: Continue to record audio when receiving a phone call (try to prevent interruptions) Uses `setPrefersNoInterruptionsFromSystemAlerts` to prevent system alerts (like phone calls) from interrupting the audio session which records audio from the microphone. * fix: Add `try` --- ios/CameraView+AVAudioSession.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/CameraView+AVAudioSession.swift b/ios/CameraView+AVAudioSession.swift index 0b1fbdb..57d0ed5 100644 --- a/ios/CameraView+AVAudioSession.swift +++ b/ios/CameraView+AVAudioSession.swift @@ -92,6 +92,12 @@ extension CameraView { .allowBluetoothA2DP, .defaultToSpeaker, .allowAirPlay]) + + if #available(iOS 14.5, *) { + // prevents the audio session from being interrupted by a phone call + try AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(true) + } + audioCaptureSession.startRunning() } catch let error as NSError { switch error.code {