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.
2
Answers
Your category is probably wrong. From the docs for
.mixWithOthers
: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.)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 byaudioSession.setActive(true)
fixed the error.