我有一个使用Xamarin开发的iOS应用程序,当应用程序没有麦克风访问权限时,如果用户尝试从应用程序访问麦克风,则我会使用AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool granted))
检查设置并显示消息。
现在,如果应用程序没有访问相机的权限,我需要做同样的事情。 我需要检查是否授予相机权限,并根据情况显示消息。 我该如何做?
我有一个使用Xamarin开发的iOS应用程序,当应用程序没有麦克风访问权限时,如果用户尝试从应用程序访问麦克风,则我会使用AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool granted))
检查设置并显示消息。
现在,如果应用程序没有访问相机的权限,我需要做同样的事情。 我需要检查是否授予相机权限,并根据情况显示消息。 我该如何做?
我已经得到了答案。这是我所做的:
AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool isAccessGranted) => {
//if has access
if(isAccessGranted)
{
//do something
}
//if has no access
else
{
//show an alert
}
});
// replace the media type to whatever you want
AVAuthorizationStatus authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
switch (authStatus)
{
case AVAuthorizationStatus.NotDetermined:
break;
case AVAuthorizationStatus.Restricted:
break;
case AVAuthorizationStatus.Denied:
break;
case AVAuthorizationStatus.Authorized:
break;
default:
throw new ArgumentOutOfRangeException();
}