我在尝试使用相机时遇到了一些问题。问题是某些设备在设置下向我显示相机条目,而另一些则没有。在那些没有出现相机开关的设备中,我无法使用相机,因为它没有权限,而且它也没有出现在启用它们的设置下。
这是它在工作设备上的外观:
这就是它在不起作用的设备中的外观。
当我截取这些屏幕截图时,应用程序应该已经请求权限,但它没有。
我还验证了这些设备没有启用限制。
有任何想法吗?
更新 1:添加代码
这是我用来显示相机的代码(它在自定义视图下,而不是本机相机视图控制器)
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];