Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Application.RequestUserAuthorization

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method RequestUserAuthorization(mode: UserAuthorization): AsyncOperation;
public static AsyncOperation RequestUserAuthorization(UserAuthorization mode);

Description

Request authorization to use the webcam or microphone on iOS.

The call of Application.RequestUserAuthorization requests permission for microphone and camera. The application shows a dialog box to the user and waits for operation to complete before being able to use these features.

Note: Use Application.HasUserAuthorization to query the result of the operation.

function Start() {
    // Request permission to use both webcam and microphone.
    yield Application.RequestUserAuthorization (UserAuthorization.WebCam | UserAuthorization.Microphone);

if (Application.HasUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)) { // we got permission. Set up webcam and microphone here. } else { // no permission. Show error here. } }
using UnityEngine;
using UnityEngine.iOS;
using System.Collections;

// Show WebCams and Microphones on an iPhone/iPad. // Make sure NSCameraUsageDescription and NSMicrophoneUsageDescription // are in the Info.plist.

public class ExampleClass : MonoBehaviour { IEnumerator Start() { findWebCams();

yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); if (Application.HasUserAuthorization(UserAuthorization.WebCam)) { Debug.Log("webcam found"); } else { Debug.Log("webcam not found"); }

findMicrophones();

yield return Application.RequestUserAuthorization(UserAuthorization.Microphone); if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { Debug.Log("Microphone found"); } else { Debug.Log("Microphone not found"); } }

void findWebCams() { foreach (var device in WebCamTexture.devices) { Debug.Log("Name: " + device.name); } }

void findMicrophones() { foreach (var device in Microphone.devices) { Debug.Log("Name: " + device); } } }

Did you find this page useful? Please give it a rating: