2014-02-21 35 views
0

我正在尝试使用ZBar来实现一些二维码读取器。 过了一段时间,我确实设法阅读,但经过几次阅读后,应用程序往往变得越来越慢(直到实际上没有响应)。 此SDK与iOS7兼容? 框架:libiconv.dylib,libinfo.dylib,QuartzCore,corevideo的,CoreMedia,AVFoundation,CoreGraphics中,UIKit中,XCTestZBar SDK在IOS7中变慢了

- (IBAction)scan:(id)sender { 
    //initialize the reader and provide some config instructions 
    ZBarReaderViewController *reader = [ZBarReaderViewController new]; 
    reader.readerDelegate = self; 

    [reader.scanner setSymbology: ZBAR_I25 
          config: ZBAR_CFG_ENABLE 
           to: 1]; 
    reader.cameraFlashMode=UIImagePickerControllerCameraFlashModeOff; 
    reader.readerView.zoom = 1.0; // define camera zoom property 

    //show the scanning/camera mode 
    [self presentModalViewController:reader animated:YES]; 
    // Do any additional setup after loading the view from its nib. 
} 
- (void) imagePickerController: (UIImagePickerController*) reader 
didFinishPickingMediaWithInfo: (NSDictionary*) info { 

    //this contains your result from the scan 
    id results = [info objectForKey: ZBarReaderControllerResults]; 

    //create a symbol object to attach the response data to 
    ZBarSymbol *symbol = nil; 

    //add the symbol properties from the result 
    //so you can access it 
    for(symbol in results){ 

     //symbol.data holds the value 
     NSString *upcString = symbol.data; 

     //print to the console 
     NSLog(@"the value of the scanned UPC is: %@",upcString); 

     NSMutableString *message = [[NSMutableString alloc] 
            initWithString: @"Scanned Barcode: "]; 

     [message appendString:[NSString stringWithFormat:@"%@ ", 
           upcString]]; 

     //Create UIAlertView alert 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle:@"Product Barcode" message: message delegate:self 
           cancelButtonTitle:@"Cancel" otherButtonTitles: nil]; 

     self.viewResult.text = upcString; 
     [alert show]; 
     //After some time 
     [alert dismissWithClickedButtonIndex:0 animated:TRUE]; 

     //make the reader view go away 
     [reader dismissModalViewControllerAnimated: YES]; 
    } 

} 

编辑:经过4个或5个读数,这是存储器和CPU的消耗 - >http://diogomend.me/images/capt.png。基督:D

+0

如果您只需要在iOS7部署我建议你使用AVFoundation的新API来检测条形码,qrcode和类似的文件 – Andrea

+0

为什么你不使用iOS7中的AVCaptureSession(natif)来扫描条形码。看看这个教程:http://www.renaudpradenc.com/?p=453 –

+0

该应用程序将不得不在iOS6上工作:(在iOS6中,我没有这个放慢速度的问题......奇怪! –

回答

2

那么,在检查这个问题Memory related issue of ZBarReaderViewController in iOS 7后,我确实设法解决了这个问题。 我已经添加了线如下:

(在我viewcontroller.h)

@property (strong,nonatomic) ZBarReaderViewController *reader; 

(在我viewcontroller.m)

if(self.reader) 
{ 
    [self.reader.readerView stop]; 
    for(UIView *subViews in self.reader.view.subviews) 
    [subViews removeFromSuperview]; 
    [self.reader.view removeFromSuperview]; 
    self.reader.view = nil; 
} 
_reader = [ZBarReaderViewController new];