Read camera permission for iOS in Xamarin

吃可爱长大的小学妹 提交于 2021-02-07 13:50:20

问题


I have an iOS app developed in Xamarin. When the app does not have permission to access the microphone, if the user tries to access the microphone from the app, I check the settings using AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool granted)) and display a message.

Now I need to do the same if the app does not have permission to access the camera. I need to check if permission is granted for camera and display a message accordingly. How can I do this?


回答1:


Did you checked this answer? Detect permission of camera in iOS I think that's the solution you are looking for :).

EDIT: Here is the highest voted answer's code ported to 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();
}



回答2:


I have got the answer. Here is what I have done:

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


来源:https://stackoverflow.com/questions/31177640/read-camera-permission-for-ios-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!