问题
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