在Xamarin中读取iOS相机权限

7

我有一个使用Xamarin开发的iOS应用程序,当应用程序没有麦克风访问权限时,如果用户尝试从应用程序访问麦克风,则我会使用AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool granted))检查设置并显示消息。

现在,如果应用程序没有访问相机的权限,我需要做同样的事情。 我需要检查是否授予相机权限,并根据情况显示消息。 我该如何做?

2个回答

5

我已经得到了答案。这是我所做的:

AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool isAccessGranted) => {                    
   //if has access              
   if(isAccessGranted)
   {
      //do something
   }
   //if has no access
   else
   {
      //show an alert
   }
});

2
你检查过这个答案了吗? 在iOS中检测相机权限 我认为那就是你要找的解决方案 :).
编辑: 以下是最高票答案的C#代码移植。
// 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();
}

谢谢。是的,我已经阅读了这个链接。我想要针对Xamarin的帮助。 - Sakina Sugra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接