【发布时间】:2015-11-26 17:33:24
【问题描述】:
我在尝试使用相机时遇到了一些问题。问题是某些设备在设置下向我显示了相机条目,而另一些则没有。在那些没有出现相机开关的设备上,我无法使用相机,因为它没有权限,而且它也没有出现在设置下以启用它们。
这是它在工作设备上的外观:
这就是它在不工作的设备中的样子。
当我截取这些屏幕截图时,应用程序应该已经请求权限,但它没有。
我还验证了这些设备没有启用限制。
有什么想法吗?
更新 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];
【问题讨论】:
-
只有在您的应用请求许可后,相机才会出现在那里。你能显示你用来请求权限的代码吗?
-
已添加。当我开始捕获会话时,该代码不会自动询问权限吗?应用程序中的其他地方我正在使用 UIImagePickerController 拍照。也许我没有正确处理权限,但是如果我之前打开了 UIImagePickerController,那么权限就被启用了?
-
我遇到了同样的问题,非常渴望找到解决方案。如果您找到解决此问题的方法,请告诉我...!
-
亚伦的回答对我有用。
-
请试试这个解决方案stackoverflow.com/a/34526211它对我有用。
标签: ios iphone ipad ios-camera