title: AVAudioSession in bluetooth switches strangely when interrupting playback of other apps
body: <p>I'm working on a VoIP app and i have handled the interruption of AVAudioSession in normal cases. <b>But i find that in bluetooth mode, when i start a call, the switching process from PlayBack to PlayAndRecord will not complete instantly. There will be a short play in low quality and loud volume during the switching time. After that, the playback will not resume even though the call is over.</b> This phenomenon appears randomly. Mostly at the beginning time, and then everything is OK. But after several times of calling, it happens again, which confuses me a lot.</p>
  
  <p>I guessed at the beginning that it might be the problem of bluetooth category, so i added the options [.allowBluetooth, .allowBluetoothA2DP]. But it did not work. Here's my code.</p>
  
  <pre class="lang-swift prettyprint-override"><code>// setting of AVAudioSession
  public static let voipCall: AudioSessionScenario = {
      if #available(iOS 10.0, *) {
          return AudioSessionScenario("voip", category: .playAndRecord, mode: .voiceChat, options: [.allowBluetooth, .allowBluetoothA2DP])
      } else {
          return AudioSessionScenario("voip", category: .playAndRecord, mode: .voiceChat, options: [.allowBluetooth])
      }
  }()
  
  // when user starts a call
  AVAudioSession.queue.async {
      AVAudioSession.entry(AudioSessionScenario.voipCall)
  }
  
  // the entry method does nothing but set the setting of sharedInstance
  if #available(iOS 10.0, *) {
      try session.setCategory(category, mode: scenario.mode, options: scenario.options)
  } else {
      AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:withOptions:error:"), with: category, with: scenario.options)
  }
  </code></pre>
  
  <p>I expect that there is no strange play in the switching process and the playback will resume after the call. <b>It works well in normal cases including speaker and wired headset. Bluetooth devices like Bose QC30 or Airpods have the unstable problem. </b>Does anyone know the reason? Thx.</p>