我们在iOS升级从7.0.6升级到7.1.0后遇到了麻烦。我没有在运行iOS 7.1的iPhone 4s,5,5c和5s上看到这个问题。所有的非碎片谈话都是如此。我发布了相机初始化代码:
- (void)initCapture
{
//Setting up the AVCaptureDevice (camera)
AVCaptureDevice* inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError* cameraError;
if ([inputDevice lockForConfiguration:&cameraError])
{
if ([inputDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus])
{
NSLog(@"AVCaptureDevice is set to video with continuous auto focus");
CGPoint autofocusPoint = CGPointMake(0.5f, 0.5f);
[inputDevice setFocusPointOfInterest:autofocusPoint];
[inputDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
}
[inputDevice unlockForConfiguration];
}
//setting up the input streams
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];
//setting up up the AVCaptureVideoDataOutput
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES;
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
//setting up video settings
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
//passing the settings to the AVCaptureVideoDataOutput
[captureOutput setVideoSettings:videoSettings];
//setting up the AVCaptureSession
captureSession = [[AVCaptureSession alloc] init];
captureSession.sessionPreset = AVCaptureSessionPresetMedium;
[captureSession addInput:captureInput];
[captureSession addOutput:captureOutput];
if (!prevLayer)
{
prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
}
NSLog(@"initCapture preview Layer %p %@", self.prevLayer, self.prevLayer);
self.prevLayer.frame = self.view.bounds;
self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer: self.prevLayer];
[self.captureSession startRunning];
}
非常感谢任何帮助......
答案 0 :(得分:1)
您使用的Apple提供的代码已过时 - 它们现已完全重写。我会试试运气并选择新的工作流程。
查看here。
答案 1 :(得分:1)
为了关闭这个帖子,除了libzxing之外,我们还使用相机扫描QR码。我们决定实现本机iOS 7.0 AVCaptureMetadataOutputObjectsDelegate而不是旧的AVCaptureVideoDataOutputSampleBufferDelegate。元数据委托更简单,更清晰,我们发现http://nshipster.com/ios7/中的示例非常有用。
答案 2 :(得分:0)
以下是诊断问题的一些想法:
if ([inputDevice lockForConfiguration:&cameraError])
没有其他情况。添加一个。cameraError
。if ([inputDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus])
没有其他情况。加一个;记录它,或在那里添加断点以在调试中进行测试。focusPointOfInterestSupported
之前,您不会检查属性setFocusPointOfInterest
的返回值。
考虑在setFocusMode
之前致电setFocusPointOfInterest
(不确定是否重要,但这就是我所拥有的)答案 3 :(得分:0)
根据neuman8的评论说libzxing的某些东西阻止了重新聚焦,我做了一些调查自己的事 我发现Decoder.mm文件中的以下行是罪魁祸首。
ArrayRef<char> subsetData (subsetBytesPerRow * subsetHeight);
似乎ArrayRef是zxing / common / Array.h文件中的一个类,它试图分配具有指定大小的数组。它似乎没有做错任何事,但我猜测大约170k char元素数组的分配可能需要一些时间,并且是阻止其他线程运行的阻塞调用的罪魁祸首。
所以,我试着用一个强力解决方案来测试这个假设。我在分配后添加了一个睡眠。
[NSThread sleepForTimeInterval:0.02];
相机再次开始聚焦,能够破译二维码。
我仍然无法找到更好的解决方法。有没有人能够更有效地分配大数组,或者有一种更优雅的方式来产生相机焦点的线程?
否则这应该解决现在的问题,即使它是丑陋的