lucaslt89 lucaslt89 - 2 months ago 24
iOS Question

iOS Camera permissions doesn't appear under settings in some devices

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:

enter image description here

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

enter image description here

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.

Any ideas?

UPDATE 1: Added code

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];
[self.captureSession addInput:videoInput];
NSLog(@"Error: %@", error);

AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
[self.captureSession addOutput:metadataOutput];
[metadataOutput setMetadataObjectsDelegate:self
[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:].