AudioQueueStart error with -16981 from background process on iOS 7

In my iOS application in all previous versions of the OS, we sometimes record audio, then sleep for a while, then record again and continue cyclically (sleep should support the battery). This worked great with iOS 7, even when the app was in the background. Now that the application is in the background, the call to AudioQueueStart cannot start recording with the error: -16981. I can’t find this error code in the documentation or on the Internet, and if I turn it into an NSError, he says: "The operation could not be completed (OSStatus error -16981.)", That not all of this is useful.

I have a theory that Apple closes the hole here; the idea was; why do you want to start recording from the background process if you are not spying? Well, with the consent of users (signed and paid!), This is exactly what we do.

So, can anyone confirm or deny that this is expected, or what I can do about it. This is a little killer for our application. I registered it as an error with Apple and will try to report the progress here.

UPDATE: October 3, 2013

Although the previous answer seemed to work for a while; now it stops working with -12985 because another application turned on the sound. This, of course, is why I need to use the mix flag.

UPDATE:

iOS 7.0.3 (and later) seems to have completely fixed this problem.

+4
source share
1 answer

After playing with various properties of the audio session, I found that the error -16981 occurs when the kAudioSessionProperty_OverrideCategoryMixWithOthers (TRUE) function is enabled. Once I set it to "0", AudioQueueStart () will succeed. So, before starting an audio session, try:

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

Obviously, this is a behavior change in iOS 7. As mentioned earlier, the documentation does not specify error code -16981.

+4
source

All Articles