Recording on iOS devices

Hi,
I have an app that is using the microphone, the app was created with unity 2020.3.37f1, and with Fmod 2.02.07

The app works fine on Windows, on Android, but on iOS, it is not recording.
The only way I found to make it record, is by editing the iOS XCode project. In the iOS
project I go to classes folder and open UnityAppController.mm. in the startUnity function, I edit this code:

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil];
    if (UnityIsAudioManagerAvailableAndEnabled())
    {
        if (UnityShouldPrepareForIOSRecording())
        {
            [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
        }
        else if (UnityShouldMuteOtherAudioSources())
        {
            [audioSession setCategory: AVAudioSessionCategorySoloAmbient error: nil];
        }
    }

    [audioSession setActive: YES error: nil];
    [audioSession addObserver: self forKeyPath: @"outputVolume" options: 0 context: nil];
    UnityUpdateMuteState([audioSession outputVolume] < 0.01f ? 1 : 0);

and turn it to this:

    AVAudioSession* audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory: AVAudioSessionCategoryAmbient error: nil];
    [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
    [audioSession setActive: YES error: nil];
    [audioSession addObserver: self forKeyPath: @"outputVolume" options: 0 context: nil];
    UnityUpdateMuteState([audioSession outputVolume] < 0.01f ? 1 : 0);

Though I’m sure there must be a way to make the Unity project, do it automatically, I just don’t know how.

Can anyone help me with that?
Thanks.

1 Like

Unfrotunately we don’t currently have a way to make Unity do this automatically and manually editing UnityAppController.mm is the recommened approach.

But then the Unity team is creating the UnityAppController.mm file, it makes sense that if you fill the “Microphone Usage Description” property in the player settings, you want to use the microphone, so they should be notified this fix is needed.