9

After recently installing iOS 16 beta 5, we are experiencing an issue with try AVAudioSession.sharedInstance().setCategory(<category>, options: .mixWithOthers), in which we get an error, and lose the connection.

Here is the error:

AVAudioSession_iOS.mm:2365 Failed to set category, error: 'what'

There is no additional information about this error. Any help would be greatly appreciated.

FYI: This only began to occur specifically in iOS Beta 5, and was previously working in iOS Beta 4.

cohen72
  • 2,830
  • 29
  • 44
  • Does anybody have the answer of this question am facing the same issue @Cohen72, if you solve it then post your answer. – Mandeep Singh Oct 14 '22 at 06:48

2 Answers2

1

Your category is probably wrong. From the docs for .mixWithOthers:

You can set this option explicitly only if the audio session category is playAndRecord, playback, or multiRoute. If you set the audio session category to ambient, the session automatically sets this option. Likewise, setting the duckOthers or interruptSpokenAudioAndMixWithOthers options also enables this option.

I expect that your category is not playAndRecord, playback, or multiroute. Many AVAudioSession configurations have non-obvious requirements that may or may not be enforced in a particular version of the OS. I highly recommend reading the docs for every AVAudioSession method you call and every constant you use. The audio frameworks are filled with things that don't do precisely what their names imply.

'what' is a 4-character code (an old way of expressing a 32-bit integer as a "string-like thing"). It means AVAudioSessionErrorCodeUnspecified (see the AudioSessionTypes.h header.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thanks for quick Response @rob-napier!! We are passing `playAndRecord` as the category, and also suspected this might be the reason, and so attempt to debug by passing various different combinations of category together with options to see if it would impact at all, however it always results in the same error. FYI: This only began occurring in iOS 16 Beta 5 (previously was working fine in iOS 16 Beta 4). – cohen72 Aug 14 '22 at 14:41
  • 1
    I'd build a MCRE in that case. Can you demonstrate this with an empty app that just calls this one line of code in Beta 5? (You'd want to open a FB immediately in that case.) If you can get this error with every combination of category and option (i.e. just `setCategory(.playback)` and nothing else), then I expect you're doing something elsewhere that's invalid, since I haven't seen folks screaming about it being 100% broken like that on Twitter yet. – Rob Napier Aug 14 '22 at 14:43
  • It's most likely we are doing something elsewhere that's invalid, we have a lot of custom code, thread usage, etc., around this specific feature in our app. I'll see if it's simply enough to build a MCRE, but most probably I will dig in a bit more to the codebase to better understand what else might be the cause. I really appreciate your help and suggestions! If/When I figure this one out, I'll be sure to post the results :) – cohen72 Aug 14 '22 at 14:51
  • 1
    @cohen72 I would file a bug in any case. It can't hurt. If something was working up to now and suddenly stopped working in a particular beta, that is something you have a _duty_ to report: your _job_ here is to be a beta tester. However, you'd _still_ need to develop a [mcve] first. – matt Aug 14 '22 at 14:52
  • @cohen72 hello there, did you find anything useful to solve your issue? thank you – dianaqqq Sep 14 '22 at 08:24
  • 3
    @dianaqqq yes, I did eventually resolve it, because we finally understood that iOS 16 internally added requirements around setting the AVAudioSession's category under certain conditions. In our case, we had called `AudioQueueStart` and while that was started, we then tried to change the category to `record`, it was throwing an error. So we changed our logic, to set the category first to `playAndRecord`, and then using `AudioQueueStart` – cohen72 Sep 15 '22 at 11:19
  • I am getting the same issue, code was working perfectly in all previous iOS versions. – Deepak Sharma Oct 12 '22 at 17:15
1

We've just hit this on iOS 16.1 (20B82). We were initially setting the category to .playback, then changed it to .playAndRecord when we needed to do recording. It was when we tried to change it back to .playback that we got the error.

I found that audioSession.setActive(false) before switching category, followed by audioSession.setActive(true) fixed the error.

Cuespeak
  • 149
  • 1
  • 13