Version: 2020.1

Application.RequestUserAuthorization

切换到手册
public static AsyncOperation RequestUserAuthorization (UserAuthorization mode);

描述

请求授权在 iOS 中使用网络摄像头或麦克风。

调用 Application.RequestUserAuthorization 时,将请求获得麦克风和摄像机的许可权。应用程序向用户显示一个对话框并等待操作完成,然后才能使用这些功能。

注意:使用 Application.HasUserAuthorization 可查询操作结果。

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); } } }