在iPad上请求相机权限 [英] Asking camera permission on iPad

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

问题描述

在应用程式中,我目前仅在检查相机权限后才拍摄照片,如下所示:

In an app, I'm currently taking a picture only after camera permissions have been checked, as follows:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized) {
    // Take picture
}else{
    // Prompt user to go into their settings and add permissions for app
}

但是,首次使用时,a)初始您想授予此应用程序的相机权限吗? 。提示没有出现,和b)应用程序没有出现在iPad的设置中隐私 - >相机。这导致不幸的情况下,无法在应用程序中允许相机权限。

However, on first use, a) the initial "Would you like to give this app camera permissions?" prompt does not appear, and b) the app doesn't appear in the iPad's settings under privacy -> camera. This leads to the unfortunate case of not being able to ever allow camera permissions in the app.

任何关于如何避免这种情况的建议都会非常感激。感谢您阅读。

Any suggestions on how to avoid this would be much appreciated. Thanks for reading.

推荐答案

您需要使用以下代码请求权限:

You need to request for permission using the following code:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
    // Take picture
}
else
{
    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
    {
       if (granted)
       {
           NSLog(@"User Granted");
       }
       else
       {
           NSLog(@"User Denied");
       }
    }];
}

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

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