From 7e18052c454b2811822286536e6f91d48d4c8fdc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 15 May 2017 11:08:24 -0400 Subject: [PATCH] Fix Bluetooth audio in calls. // FREEBIE --- Signal/src/call/CallAudioService.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Signal/src/call/CallAudioService.swift b/Signal/src/call/CallAudioService.swift index be387e2ed..cf0ebba2f 100644 --- a/Signal/src/call/CallAudioService.swift +++ b/Signal/src/call/CallAudioService.swift @@ -98,14 +98,15 @@ import AVFoundation if call.hasLocalVideo { setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVideoChat, - options: .defaultToSpeaker) + options: [.defaultToSpeaker]) } else if call.isSpeakerphoneEnabled { setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, - options: .defaultToSpeaker) + options: [.defaultToSpeaker]) } else { setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, - mode: AVAudioSessionModeVoiceChat) + mode: AVAudioSessionModeVoiceChat, + options: [.allowBluetooth]) } } @@ -150,7 +151,7 @@ import AVFoundation } else { setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, - options: .mixWithOthers) + options: [.mixWithOthers, .allowBluetooth]) } // HACK: Without this async, dialing sound only plays once. I don't really understand why. Does the audioSession @@ -299,6 +300,8 @@ import AVFoundation private func setAudioSession(category: String, mode: String? = nil, options: AVAudioSessionCategoryOptions = AVAudioSessionCategoryOptions(rawValue: 0)) { + assert(Thread.isMainThread) + do { if #available(iOS 10.0, *), let mode = mode { try AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options)