I am trying to implement some qr code reader using ZBar. After a while I did manage to do reading, but after several readings the app tends to get slower and slower (until practically unresponsive). This SDK is compatible with iOS7 ? Frameworks : libiconv.dylib,libinfo.dylib, QuartzCore, CoreVideo,CoreMedia,AVFoundation,CoreGraphics,UIKit,XCTest
- (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];
}
}
EDIT : After 4 or 5 readings, this is the memory and CPU consumption -> http://diogomend.me/images/capt.png. Christ :D
Well, after checking this issue Memory related issue of ZBarReaderViewController in iOS 7, I did manage to solve the problem. The lines I've added are the following:
(in my viewcontroller.h)
@property (strong,nonatomic) ZBarReaderViewController *reader;
(in my 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];