7

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

现在,如果应用程序无权访问相机,我也需要这样做。我需要检查是否授予相机权限并相应地显示一条消息。我怎样才能做到这一点?

4

2 回答 2

5

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

AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool isAccessGranted) => {                    
   //if has access              
   if(isAccessGranted)
   {
      //do something
   }
   //if has no access
   else
   {
      //show an alert
   }
});
于 2015-07-02T10:22:03.173 回答
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();
}
于 2015-07-02T09:38:40.927 回答