Application.RequestUserAuthorization does not prompt for microphone access permission in iOS

Hi everyone,

I created a new project using Intel based Editor version 2022.3.2f1, and used Vivox for audio chats. I have a game object that requests for microphone permission before initializing Vivox. The request permission function is invoked in the start method however, it never shows the mic permission popup in iOS build.

I have used similar code before when using Intel based Editor version 2021.3.11f1 also with Vivox, where it worked everytime but this time with Intel based Editor version 2022.3.2f1, I am not getting the popup. However, Application.HasUserAuthorization() works. Also, I tried running this project in another Mac device, also using Intel based Editor version 2022.3.2f1, the iOS build from that computer gives the popup for mic permission. I am quite confused why this is happening. Has anyone ever come across such issue?

Any pointers would be great. Thanks!

I have attached the my permission request code below:

using UnityEngine;
#if UNITY_ANDROID
    using UnityEngine.Android;
#endif

public class Room : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
    }

    public void RequestMicPermission()
    {
        if (!HasMicPermission())
        {
            Debug.Log("User does not have microphone permission");
#if UNITY_ANDROID
    Debug.Log("Requesting Android mic permission");
    Permission.RequestUserPermission(Permission.Microphone);
#endif
#if UNITY_IOS
            Debug.Log("Requesting iOS mic permission");
            Application.RequestUserAuthorization(UserAuthorization.Microphone);
#else
            Debug.Log("Requesting permission in else block");
            Application.RequestUserAuthorization(UserAuthorization.Microphone);
#endif

            if (HasMicPermission())
            {
                Debug.Log("User has enabled microphone");
            }
            else
            {
                Debug.Log("User did not provide microphone permission");
            }
        }
        else
        {
            Debug.Log("User has microphone permission");
        }
    }

    public bool HasMicPermission()
    {
#if UNITY_ANDROID
    Debug.Log("Checked Android mic permission");
    return Permission.HasUserAuthorizedPermission(Permission.Microphone);
#endif
#if UNITY_IOS
    Debug.Log("Checked iOS mic permission");
    return Application.HasUserAuthorization(UserAuthorization.Microphone);
#else
        Debug.Log("Checked else mic permission");
        return Application.HasUserAuthorization(UserAuthorization.Microphone);
#endif
    }
}

Hello,

Would you kindly please report this issue via the Bug Reporter tool?
https://unity.com/releases/editor/qa/bug-reporting

I’ve tried looking to see if this a known issue on our side, but personally reading through it might need to looked at if this is something from our side.

Please make sure to write the exact steps needed to be taken so that the reproduction would be visually seen. Also make sure to attach a reproduction project and any visual material so that when testing our CQA team can verify that they got the same results. If you can, please use this template:

How to reproduce:

  1. Open the attached project
  2. Do this
  3. Do that
  4. Select this
  5. Observe that

Expected result: Something is visible, something is printed or something happens
Actual result: The opposite of what I expect happens

Reproducible with: Editor version I am using (e.g: 2021.3.xf1)

Reproduced on: The OS I am on (e.g: Windows 11, macOS Ventura 13.1 (Intel/Silicon))

Hi,

I was investigating more and found out there was an issue with the following flags inside Preprocessor.h:

#define UNITY_USES_WEBCAM 0
#define UNITY_USES_MICROPHONE 0

They are both set to 0 so the following condition never returns true ins AVCapture:

extern "C" int UnityGetAVCapturePermission(int captureType)
{
    NSString* mediaType = MediaTypeFromEnum(captureType);
    if (mediaType == nil)
        return avCapturePermissionDenied;

#if !PLATFORM_TVOS && (UNITY_USES_WEBCAM || UNITY_USES_MICROPHONE)
    NSInteger status = AVAuthorizationStatusAuthorized;
    status = [AVCaptureDevice authorizationStatusForMediaType: mediaType];

    if (status == AVAuthorizationStatusNotDetermined)
        return avCapturePermissionUnknown;
    else if (status == AVAuthorizationStatusAuthorized)
        return avCapturePermissionGranted;
#endif

    return avCapturePermissionDenied;
}

extern "C" void UnityRequestAVCapturePermission(int captureType, void* userData)
{
#if !PLATFORM_TVOS && (UNITY_USES_WEBCAM || UNITY_USES_MICROPHONE)
    NSString* mediaType = MediaTypeFromEnum(captureType);
    if (mediaType == nil)
        return;

    [AVCaptureDevice requestAccessForMediaType: mediaType completionHandler:^(BOOL granted) {
        UnityReportAVCapturePermission(userData);
    }];
#endif
}

I have to manually set either of UNITY_USES_WEBCAM or UNITY_USES_MICROPHONE as 1 in order for this to work. So, I am quite not sure if this is a bug in Unity editor or something that I missed for these flags to be set correctly. Thanks!

How to reproduce:

  1. Create a fresh new project and open in iOS as target platform
  2. Add a gameobject with a script
  3. Inside the script, use the following code:
// Start is called before the first frame update
    void Start()
    {
        StartCoroutine(MicPerms());
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator MicPerms()
    {
        yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
    }
  1. Add Microphone usage description under Player Settings for iOS
  2. Build for iOS and run in an iOS device (my iOS version is 16.5.1)

Expected result: Once the game runs, it should ask for microphone permission
Actual result: It does not ask for microphone permission

Reproducible with: Editor version 2022.3.4f1 (Intel build)

Reproduced on: macOS Ventura 13.4.1 (Silicon)