This article explains how to request and check microphone permissions in macOS/iOS using Unity, including required steps for setting the NSMicrophoneUsageDescription in the info.plist. It is useful for resolving issues with microphone access when using Unity or integrating Vivox.
Application.RequestUserAuthorization
Application.RequestUserAuthorization is called to request permission for microphone. The application will then display a dialog box that includes the text provided in the info.plist and waits for the operation to complete before returning. Use Application.HasUserAuthorization to query the result of the operation.
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
if (Application.HasUserAuthorization(UserAuthorization.Microphone))
{
Debug.Log("Microphone found");
}
else
{
Debug.Log("Microphone not found");
}
Add Usage Text to info.plist
On macOS/iOS, the property NSMicrophoneUsageDescription must be included in your info.plist. This property provides a text description that will be displayed when requesting microphone permission. If you request permissions and this value is not set, your application will terminate with an error.
Preferred Method
You can add this value through the Unity Player Settings as shown in the following image:
Alternate Method
Edit the info.plist file after the Xcode project generation is complete, adding the following lines, where your microphone usage description is substituted for This app requires microphone access to record audio.
<key>NSMicrophoneUsageDescription</key> <string>This app requires microphone access to record audio.</string>