我正在尝试使用ZBar实现一些qr代码阅读器。 过了一段时间我确实设法做了阅读,但经过几次阅读后,应用程序往往变得越来越慢(直到几乎没有响应)。 这个SDK与iOS7兼容? 框架: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];
}
}
编辑:读取4或5次后,这是内存和CPU消耗 - > http://diogomend.me/images/capt.png。基督:D
答案 0 :(得分: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];