Disable AVAudioSession at application startup

This commit is contained in:
Benoit Martins 2024-01-18 15:30:42 +01:00 committed by QuentinArguillere
parent 9ef28d00f6
commit dedd68326a
2 changed files with 22 additions and 2 deletions

View file

@ -76,6 +76,12 @@ struct CallView: View {
}
}
}
.onAppear {
callViewModel.enableAVAudioSession()
}
.onDisappear {
callViewModel.disableAVAudioSession()
}
}
}

View file

@ -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() {