某些设备的设置下不会显示iOS相机权限

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

这就是它在工作的设备上的外观:

在这里输入图像说明

这就是它在不起作用的设备中的外观。

在这里输入图像说明

当我把这些截图,应用程序应该已经要求权限,但它没有。

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

有任何想法吗?

更新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]; 

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

 [AVCaptureDevice requestAccessForMediaType:completionHandler:] 

步骤1:使用以下键(不带引号)在您的info.plist上给出正确的摄像头消息访问消息:

 "Privacy - Camera Usage Description" 

步骤2:对于Objective-C / SWIFT,您需要请求相机访问权限

Objective-C的

 [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if (granted == true) { //[self presentViewController : picker animated:YES completion:NULL]; //Do your stuff } else { UIAlertView *cameraAlert = [[UIAlertView alloc]initWithTitle:STR_APPLICATION_TITLE message:STR_ALERT_CAMERA_DENIED_MESSAGE delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil]; [cameraAlert show]; NSLog(@"denied"); } }]; 

迅速

 AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (videoGranted: Bool) -> Void in if (videoGranted) { //Do Your stuff here } else { // Rejected Camera } })