Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read camera permission for iOS in Xamarin

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?

like image 883
Sakina Sugra Avatar asked Jul 02 '15 07:07

Sakina Sugra


2 Answers

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
   }
});
like image 164
Sakina Sugra Avatar answered Sep 30 '22 05:09

Sakina Sugra


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();
}
like image 22
Roosevelt Avatar answered Sep 30 '22 05:09

Roosevelt