Question

I'm trying to start a kAudioSessionCategory_RecordAudio after my app is woken up in the background but not forefront (like during a significant location change, I have seen other apps in the store do this so I know it is possible). However whenever I try to start the audio session like so

CheckError(AudioQueueStart(queue, NULL), "AudioQueueStart failed");

I get this error:

Error: AudioQueueStart failed (-12985)

So I read up on that but only suggestion is setting the audio session to active AudioSessionSetActive(YES) but that also fails with a '!cat' error. Apparently you can try to toggle the active state of the audio session but that hasn't worked for me.

I have the audio background mode plist flag set and starting an audio session while my app is forefront then switching to another app works (shows the red bar showing that it is recording). Its just starting the audio session while the app isn't forefront is the issue.

Does anyone have a sample project I could look at demonstrating starting a recording audio session in the background?

Note: I am looking for a solution that uses audio queues as I need the audio in buffers, not a file.

Was it helpful?

Solution

It turns out that Apple's SpeakHere sample code with some modifications will start recording audio in the background if you just add the audio multitasking flag to info.plist and add the appropriate significant location change APIs. You might look https://github.com/benvium/SpeakHere for an updated version of SpeakHere since Apple hasn't updated it in awhile.

OTHER TIPS

Currently, iOS does not allow starting an audio session or audio recording in the background. An app has to start audio in the foreground, but can just throw away any recorded audio data until needed, which could be in the background when using the appropriate background modes and audio session.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top