7

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Sakina Sugra
  • 133
  • 1
  • 8

2 Answers2

5

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
   }
});
Xavier Peña
  • 7,399
  • 9
  • 57
  • 99
Sakina Sugra
  • 133
  • 1
  • 8
2

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();
}
Community
  • 1
  • 1
Adam Ivancza
  • 2,459
  • 1
  • 25
  • 36