4

In my iOS app on all previous versions of the OS, we record audio occasionally, then sleep for a while, then record again, and cycle for ever (sleep is to maintain battery). This worked fine up to iOS 7, even when the app was in background. Now, when the app is in the background the call to AudioQueueStart fails to start recording with an error: -16981. I can't seem to find this error code in the documentation or on the Web, and if I turn it into an NSError, it says "The operation couldn’t be completed. (OSStatus error -16981.)", which isn't all that helpful.

I have a theory that Apple are closing a hole here; the idea being; why would you want to start recording from a background process, unless you are spying? Well, with the users consent (signed and paid for!), that's exactly what we are doing.

So; can anyone confirm or deny that this is expected, or what I might be able to do about it. It's a bit of a killer for our app. I have filed it as a bug with Apple, and will try to report progress here.

UPDATE: 3rd October 2013

Although the previous answer seemed to work for this for a while; it has stopped working now with -12985, which is because another app has turned on audio. This is of course why I need to use the mixing flag.

UPDATE:

iOS 7.0.3 (and later) seem to have fixed this issue completely.

  • Really? It's a programming question, whereas AskDifferent seems to be more for power users rather than developers. I'm hoping that someone might know what a -16981 from the AudioQueueStart function might mean, and how to fix it. – Stephen Starkie Sep 22 '13 at 21:06
  • I'm not familiar with iOS but if there are changes to the OS I thought that you would get more competent help at apple@stackexhange. But blame my bad english skills. I misunderstood the part that that page is also for software related questions. – xQuare Sep 22 '13 at 22:12
  • Hit the same issue on iOS 7. – IPhone Guy Sep 22 '13 at 22:58
  • If you can list some of the code you are using to illustrate how you are calling AudioQueueStart - we might be able to offer a workaround or at least confirm we're seeing the same errors as you. – bmike Sep 22 '13 at 23:48
  • Apple fixed this issue in iOS 7.0.3 – Stephen Starkie Feb 12 '15 at 15:25

1 Answers1

4

After playing with different audio session properties, I found that -16981 error takes place when kAudioSessionProperty_OverrideCategoryMixWithOthers is enabled (TRUE). As soon, as I set it to '0', AudioQueueStart() executes successfully. So, before starting the audio session try:

UInt32 allowMixing = 0;
status = AudioSessionSetProperty (
                      kAudioSessionProperty_OverrideCategoryMixWithOthers,
                      sizeof (allowMixing),
                      &allowMixing);

Clearly, this is behavior change in iOS 7. As it was mentioned before, the documentation does not list -16981 error code.

IPhone Guy
  • 699
  • 7
  • 6
  • Well done; that worked. Looks like its a genuine bug, so I'll add the information to the Apple bug. – Stephen Starkie Sep 24 '13 at 09:43
  • Since trying this, I have of course found that we really need mixing on in the general case, so although I can gracefully degenerate on iOS 7 to turn it off if I can't turn on Audio in the background, this is still very much a bug in the Apple code, and I'm still on the case with them – Stephen Starkie Oct 04 '13 at 15:39
  • Any progress on this? I'm working on a MIDI app that sends MIDI Clock messages even while in the background. It was working fine in iOS 6, but with iOS7, it will no longer run when minimized. I'm using Xamarin, so I wasn't sure if this was an Apple bug or a Xamarin one, so any further details you can give would be appreciated.. – Joshua Barker Oct 12 '13 at 05:08