9

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.

2 Answers2

4

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.

0

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.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • 2
    How does an app like GPS navigation work in a situation where it isn't currently speaking a direction then a user switches to the music app and plays music until the GPS navigation app speaks a new direction then the music app takes over the speaker again. I assume if you can start playback while your app is in the background you can start to record. – audioBackgrounder May 31 '13 at 13:11
  • @hotpaw2, the live app of "sleep talk recorder" perfectly works and support to record whole day in background. So there should be a way that allows to be recorded in background for whole day. here is the live app linkage: https://itunes.apple.com/en/app/sleep-talk-recorder/id391767653?mt=8 – LiangWang Dec 23 '15 at 02:29
  • Perhaps those apps enable their audio session when in the foreground and before going into the background all day. – hotpaw2 Dec 23 '15 at 03:53