2012-10-12 70 views
0

我正在使用zxing库读取QR码的应用程序。我有ZxingWidgetController问题 - 显示视图时,应用程序处于后台/未激活状态(例如屏幕锁定),相机中的图像未显示在屏幕上 - 只有背景可见,并且扫描仪看起来不工作。zXing(iOS版)黑白屏幕错误

当我再次调用initCapture方法,从相机一点点延迟视频显示后,但在这种情况下,每次当应用程序失去活性,我需要时间来重新初始化扫描仪 - 这种行为是不舒服的。

这个bug可以在几乎所有的应用上重复使用zXing,所以我想这是一些zXing的bug。

斑马线initCapture方法的代码是:

- (void)initCapture { 
#if HAS_AVFF 
    AVCaptureDeviceInput *captureInput = 
    [AVCaptureDeviceInput deviceInputWithDevice: 
      [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] 
              error:nil]; 
    if(!captureInput) 
    { 
     NSLog(@"ERROR - CaptureInputNotInitialized"); 
    } 


    AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; 
    captureOutput.alwaysDiscardsLateVideoFrames = YES; 
    if(!captureOutput) 
    { 
     NSLog(@"ERROR - CaptureOutputNotInitialized"); 
    } 


    [captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; 

    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 

    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 

    [captureOutput setVideoSettings:videoSettings]; 
    self.captureSession = [[[AVCaptureSession alloc] init] autorelease]; 
    self.captureSession.sessionPreset = AVCaptureSessionPresetMedium; // 480x360 on a 4 

    if([self.captureSession canAddInput:captureInput]) 
    { 
     [self.captureSession addInput:captureInput]; 
    } 
    else 
    { 
     NSLog(@"ERROR - cannot add input"); 
    } 
    if([self.captureSession canAddOutput:captureOutput]) 
    { 
     [self.captureSession addOutput:captureOutput]; 
    } 
    else 
    { 
     NSLog(@"ERROR - cannot add output"); 
    } 

    [captureOutput release]; 

    if (!self.prevLayer) 
    { 
     [self.prevLayer release]; 
    } 
    self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession]; 

    // NSLog(@"prev %p %@", self.prevLayer, self.prevLayer); 
    self.prevLayer.frame = self.view.bounds; 
    self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [self.view.layer addSublayer: self.prevLayer]; 

    [self.captureSession startRunning]; 
#endif 
} 

也许你们知道什么是错的?

回答

0

我不明白你的问题。如果应用程序在后台/不活动,当然它不能工作。你应该说清楚。

+0

你有权利 - 我正在写关于情况,当应用程序在后台,而zxing初始化,然后移动到前面。 – Thaven