Don't crash when incoming call on NonCallKit iOS10

Previous logic assumed "VoiceChat" mode, but when the ringer goes off,
we set "SoloAmbient" which is incompatible with that mode, causing
assertion failure.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 43e7defa28
commit a328759f0d

@ -63,7 +63,8 @@ import Foundation
mode: AVAudioSessionModeVoiceChat, mode: AVAudioSessionModeVoiceChat,
options: .defaultToSpeaker) options: .defaultToSpeaker)
} else { } else {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord) setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVoiceChat)
} }
} }
@ -185,28 +186,20 @@ import Foundation
} }
private func setAudioSession(category: String, private func setAudioSession(category: String,
mode: String, mode: String? = nil,
options: AVAudioSessionCategoryOptions) { options: AVAudioSessionCategoryOptions = AVAudioSessionCategoryOptions(rawValue: 0)) {
do { do {
if #available(iOS 10.0, *) { if #available(iOS 10.0, *), let mode = mode {
try try AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options)
AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options) Logger.debug("\(self.TAG) set category: \(category) mode: \(mode) options: \(options)")
} else { } else {
try try AVAudioSession.sharedInstance().setCategory(category, with: options)
AVAudioSession.sharedInstance().setCategory(category, with: options) Logger.debug("\(self.TAG) set category: \(category) options: \(options)")
} }
Logger.debug("\(self.TAG) set category: \(category) options: \(options)")
} catch { } catch {
let message = "\(self.TAG) in \(#function) failed to set category: \(category) with error: \(error)" let message = "\(self.TAG) in \(#function) failed to set category: \(category) with error: \(error)"
assertionFailure(message) assertionFailure(message)
Logger.error(message) Logger.error(message)
} }
} }
private func setAudioSession(category: String) {
// FIXME Why this default mode? It doesn't work with e.g. "SoloAmbient", causing `AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options)` to err
setAudioSession(category:category,
mode:AVAudioSessionModeVoiceChat,
options:AVAudioSessionCategoryOptions(rawValue: 0))
}
} }

Loading…
Cancel
Save