Feat: Type-safe configureAVAudioSession function that ensures compatibility with AVAudioSessionModes and other customizations #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@hirbod This is my first time contributing to open-source... like ever. And I should also add that this is my first time coding in Obj-C.... So please feel free to crush my soul on how I did all of this lmfao...
The gist of it is, after reading all the docs: https://developer.apple.com/documentation/avfaudio/avaudiosession, it became clear that each
AVAudioSessionCategory
could only be used with specificAVAudioSessionModes
. I was pretty thorough in making sure that I have the compatible modes with each category.In order to make this type-safe, I needed to combine them into one function. I also used this to change the types of
AVAudioSessionMode
andAVAudioSessionCategory
to anenum
type so that could properly get good developer experience tool tips when mousing over each category. For example:Additionally, you'll note here that the

setCategory
function had multiple different parametersI took my best shot at implementing this level of customization.
An example of this new function would be:
I also marked the
setCategory
function and thesetMode
function as deprecated using this new API.Among other changes, it would appear that the previously had
Alarm
category is no longer listed, and theAudioProcessing
category is listed as deprecated. https://developer.apple.com/documentation/avfaudio/avaudiosession/category-swift.structSo I removed the
Alarm
option and flagged theAudioProcessing
as deprecated. (Note that you actually did not have it in your native code anyway...).One last comment... I noticed while studying
react-native-vision-camera
Audio Session setup he has this code:So I added this plus one other option I ran across in the docs.
So... the kicker... I compiled the app and did a little bit of testing, I worked through a few compile errors I missed (small things) and everything seems to be not crashing and the function appears to be calling correctly on iOS.
That being said.... You may want to review my code and test it somehow... Sorry for not knowing a lot, I just really wanted to help out with what I was trying to accomplish...