Read camera permission for iOS in Xamarin
Asked Answered
A

2

8

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?

Awildaawkward answered 2/7, 2015 at 7:2 Comment(0)
F
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();
}
Falconiform answered 2/7, 2015 at 9:38 Comment(1)
Thanx. Yes I have read this link. I wanted help in specific to Xamarin.Awildaawkward
A
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
   }
});
Awildaawkward answered 2/7, 2015 at 10:22 Comment(0)
F
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();
}
Falconiform answered 2/7, 2015 at 9:38 Comment(1)
Thanx. Yes I have read this link. I wanted help in specific to Xamarin.Awildaawkward

© 2022 - 2025 — McMap. All rights reserved.