iOS相机权限不会出现在某些设备的设置下 [英] iOS Camera permissions doesn't appear under settings in some devices

查看:204
本文介绍了iOS相机权限不会出现在某些设备的设置下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用相机时遇到了一些问题。问题是有些设备会在设置下显示Camera条目,而其他设备则不会。在那些没有出现Camera开关的设备中,我无法使用相机,因为它没有权限,并且它也不会出现在设置下以启用它们。

I'm having some issues trying to use the camera. The problem is that some devices show me the Camera entry under settings, and some others don't. In those devices where the Camera switch doesn't appear, I'm not able to use the camera, since it doesn't have permissions, and it also doesn't appear under settings to enable them.

这是它在有效设备上的外观:

This is how it looks on a device that works:

这就是它在不起作用的设备中的样子。

And this is how it looks in devices that doesn't work.

当我拍摄这些截图时,应用程序应该已经要求权限,但事实并非如此。

When I took those screenshots, the application should've asked for permissions already, but it didn't.

我还验证了这些设备没有启用限制。

I also verified that those devices doesn't have Restrictions enabled.

有任何想法吗?

更新1:添加代码

这是代码I用于显示相机(它在自定义视图下,而不是原生相机视图控制器)

This is the code I'm using to show the camera (it's under a custom view, not the native camera view controller)

self.captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if(videoInput)
{
    [self.captureSession addInput:videoInput];
}
else
{
    NSLog(@"Error: %@", error);
}

AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self
                                     queue:dispatch_get_main_queue()];
[metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeQRCode]];

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
previewLayer.frame = self.view.layer.bounds;
UIView * previewView = [[UIView alloc] initWithFrame:self.view.frame];
[previewView.layer addSublayer:previewLayer];
[self.view addSubview:previewView];
[self.view sendSubviewToBack:previewView];

[self.captureSession startRunning];


推荐答案

您需要在开会前请求许可。使用

You need to request permission before opening a session. Use

[AVCaptureDevice requestAccessForMediaType:completionHandler:]

这篇关于iOS相机权限不会出现在某些设备的设置下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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