I'm trying to play the voice using a bluetooth device using AVAudioSession. Here is my code which I've tried putting in both appdelegate.swift's didFinishLaunchingWithOptions
and viewcontroller.swift (once at a time)
import AVFoundation
var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.AllowBluetooth, error: nil)
So the code executes perfectly but does not use the connected bluetooth device. Actually, I opened control center on iPhone which says audio source as bluetooth device when app is not opened, but bluetooth device option disappears as soon as app is opened...
The rest of code(if thats of any use) is-
var engine = AVAudioEngine()
var input = engine.inputNode
var output = engine.outputNode
var format = input.inputFormatForBus(0)
var error:NSError?
var audioSession:AVAudioSession = AVAudioSession.sharedInstance() engine.startAndReturnError(&error)
It basically is a live audio player, which takes voice from mic and plays it to AUX, speaker, (bluetooth)