在 Xamarin 中读取 iOS 的相机权限 [英] Read camera permission for iOS in Xamarin

查看:31
本文介绍了在 Xamarin 中读取 iOS 的相机权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Xamarin 开发的 iOS 应用.当应用程序没有访问麦克风的权限时,如果用户尝试从应用程序访问麦克风,我会使用 AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool grant)) 检查设置并显示一条消息.

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?

推荐答案

您是否检查过这个答案?在iOS中检测相机的权限我认为这就是您正在寻找的解决方案:)

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

这是移植到 C# 的最高投票答案的代码

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();
}

这篇关于在 Xamarin 中读取 iOS 的相机权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆