尝试打开相机视图时zbar冻结

时间:2014-04-25 08:35:59

标签: ios barcode-scanner zbar-sdk

我使用zbar sdk扫描条形码。问题是有时在尝试打开摄像机视图时会冻结。可能需要1-4分钟。它太长而且很烦人,但有时会很快打开。我该如何解决这个问题?感谢。

-(void)barcodeRead
{
    reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentViewController: reader
                       animated: YES completion:nil];

}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;
    // EXAMPLE: do something useful with the barcode image
    if(whichbtn==1){pushed=1;
        resultText1.text=symbol.data;
        resultImage1.image= [info objectForKey: UIImagePickerControllerOriginalImage];
    }else{if(whichbtn==2){pushed=1;
        resultText2.text=symbol.data;
        resultImage2.image= [info objectForKey: UIImagePickerControllerOriginalImage];
    }
    }
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissViewControllerAnimated: YES completion:nil];


}

1 个答案:

答案 0 :(得分:1)

- (void)viewDidLoad
{
    [super viewDidLoad];

    reader = [ZBarReaderViewController new];
}

//将此行放在viewDidLoad方法中。