iOS 相机权限不会出现在某些设备的设置下

标签 ios iphone ipad ios-camera

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

这是它在可用设备上的样子:

enter image description here

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

enter image description here

当我截取这些屏幕截图时,应用程序应该已经请求权限,但它没有。

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

有什么想法吗?

更新 1:添加代码

这是我用来显示相机的代码(它在自定义 View 下,而不是 native 相机 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];

最佳答案

您需要在打开 session 之前请求许可。使用

[AVCaptureDevice requestAccessForMediaType:completionHandler:]

关于iOS 相机权限不会出现在某些设备的设置下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32332313/

相关文章:

android - 电晕函数和变量

objective-c - 在 NSMutableArray 中观察计数

iphone - iOS 11.1 游戏顶部和底部触摸无响应

iphone - 如何使用 ABAddressBook 删除 iPhone 通讯录中的记录?

iOS 项目无法编译,只是在复制 swiftdocs 时停止且没有错误

ios - 是否可以在 swift 2 中隐藏 NSURL tel 函数中的号码?

iphone - 一个 Xcode 管理器中有多个证书/配置文件?

ios - 在 iPad 中从纵向模式切换到横向模式时如何正确加载图像和按钮

iphone - 如何以编程方式获取iphone的IP地址

iphone - iOS 4和5的兼容性:提示用户更新iOS