From dedd68326a17d3939423b6dff7ac1dee1337d33b Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 18 Jan 2024 15:30:42 +0100 Subject: [PATCH] Disable AVAudioSession at application startup --- Linphone/UI/Call/CallView.swift | 6 ++++++ Linphone/UI/Call/ViewModel/CallViewModel.swift | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index 3e302e8b7..eafdae478 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -76,6 +76,12 @@ struct CallView: View { } } } + .onAppear { + callViewModel.enableAVAudioSession() + } + .onDisappear { + callViewModel.disableAVAudioSession() + } } } diff --git a/Linphone/UI/Call/ViewModel/CallViewModel.swift b/Linphone/UI/Call/ViewModel/CallViewModel.swift index 4f7aeb8f4..8e98b4914 100644 --- a/Linphone/UI/Call/ViewModel/CallViewModel.swift +++ b/Linphone/UI/Call/ViewModel/CallViewModel.swift @@ -53,12 +53,26 @@ class CallViewModel: ObservableObject { init() { do { try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .voiceChat, options: .allowBluetooth) + } catch _ { + + } + resetCallView() + } + + func enableAVAudioSession(){ + do { try AVAudioSession.sharedInstance().setActive(true) } catch _ { } - - resetCallView() + } + + func disableAVAudioSession(){ + do { + try AVAudioSession.sharedInstance().setActive(false) + } catch _ { + + } } func resetCallView() {