Zbar SDK 和 ios7/xcode 5 - 应用程序达到 100% cpu 使用和内存超过 100MB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19019607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Zbar SDK and ios7/xcode 5 - App is reaching 100% cpu use and memory more than 100MB
提问by RGRG
We are using Zbar bar code reader from last 2 years. With iOS 7 and Xcode 5, after scanning 5 bar codes the app is reaching 100 % cpu use for iOS 7 device(I can see that in Xcode debug mode) and app become less responsive. We never had issue in earlier iOS versions, everything worked fine.
我们使用的是过去 2 年的 Zbar 条码阅读器。使用 iOS 7 和 Xcode 5,在扫描 5 个条码后,应用程序的 CPU 使用率达到 100%,用于 iOS 7 设备(我可以在 Xcode 调试模式下看到)并且应用程序响应速度变慢。我们在早期的 iOS 版本中从未遇到过问题,一切正常。
Is thing changed in iOS 7 related to camera launching and ZBar SDK is not updated? Is anyone else facing same issue with iOS 7?
iOS 7 中与相机启动相关的事情是否发生了变化并且 ZBar SDK 未更新?有没有其他人在使用 iOS 7 时遇到同样的问题?
回答by joaquin custodio
Solved doing this:
in the viewdidload
解决了这个问题:在 viewdidload
readerqr = [ZBarReaderViewController new];
readerqr.readerDelegate = self;
readerqr.showsHelpOnFail = NO;
ZBarImageScanner *scanner = readerqr.scanner;
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology: ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 1];
// you can use this to support the simulator
if(TARGET_IPHONE_SIMULATOR) {
cameraSim = [[ZBarCameraSimulator alloc]
initWithViewController: self];
cameraSim.readerView = readerView;
}
create ZBarReaderViewController *readerqr;
as a property of your viewcontroller.
创建ZBarReaderViewController *readerqr;
为您的视图控制器的属性。
to use it:
使用它:
-(void) showqr:(id)sender
{
[self presentViewController:readerqr animated:YES completion:nil];
return;
}
This way works, no leak, no cpu 100%
这种方式有效,无泄漏,无 CPU 100%
回答by dlavender
After seeing the same issue,
看到同样的问题后,
I moved from
我从
ZBarReaderViewController
ZBarReaderViewController
to
到
ZBarReaderView
ZBarReaderView
The disappointing part of this, though, is if you are using features like Overlay in the ZBarReaderViewController, you have to recode how that all works and you have to implement things like starting and stopping the scanner, manually.
然而,令人失望的部分是,如果您在 ZBarReaderViewController 中使用诸如 Overlay 之类的功能,您必须重新编码所有工作方式,并且必须手动实现诸如启动和停止扫描仪之类的功能。
But essentially, you need something like this in your IBAction:
但本质上,您的 IBAction 中需要这样的东西:
ZBarReaderView *reader = [ZBarReaderView new];
[self.view addSubview:reader];
reader.readerDelegate = self;
reader.tracksSymbols=YES;
ZBarImageScanner *scanner = reader.scanner;
reader.tag = 99999999;
// the important part here is to START the scanning
// 这里的重要部分是开始扫描
[reader start];
Also, remember to change your delegate in your header to ZBarReaderViewDelegate
另外,请记住将标题中的委托更改为 ZBarReaderViewDelegate
Also, the delegate "method" that gets called, at least in my code, is now (versus the imagePickerController)
此外,被调用的委托“方法”,至少在我的代码中,现在是(相对于 imagePickerController)
-(void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
for(ZBarSymbol *sym in syms) {
[view stop];
[self closeCameraScanner];
// I am also setting reader to NIL but I don't really know if this is necessary or not.
reader=nil;
}
}
-(void)closeCameraScanner{
UIView * v = [self.view viewWithTag:99999999];
if (nil != v) {
[v removeFromSuperview];
}
[self.view endEditing:YES];
}
So, that's a quick and dirty way to do this. I have some additional code for manually creating the overlay and for limiting the scan crop but as far as simply getting it running, this did the trick for me.
所以,这是一种快速而肮脏的方式来做到这一点。我有一些额外的代码用于手动创建叠加层和限制扫描裁剪,但只要让它运行,这对我来说就成功了。
回答by HMHero
I solved the problem that Barry Mc G had.
我解决了 Barry Mc G 遇到的问题。
I had the same issues even after patched zBar SDK with iOS7 from http://nerdvision.net/app-development/ios/zbar-sdk. ( 5th - 6th time opening the page it freezes at 100% CPU.)
即使在使用来自http://nerdvision.net/app-development/ios/zbar-sdk 的iOS7 修补 zBar SDK 后,我也遇到了同样的问题。(第 5 到第 6 次打开页面时它会冻结在 100% CPU。)
Whether you subclass ZBarViewController or use it directly, you present the view controller and dismiss it later when you're done with the scanner. I found the reason why this happens and the reason was I didn't stop the video streaming. In ZBarReaderView, there's a function - (void)stop; and if you run this function after you are done with the scanner, you won't see the problem ( 5th - 6th time opening the page it freezes at 100% CPU.). At least in my case it worked and hope it works for you as well.
无论你是 ZBarViewController 的子类还是直接使用它,你都会呈现视图控制器,并在你完成扫描仪后关闭它。我找到了发生这种情况的原因,原因是我没有停止视频流。在 ZBarReaderView 中,有一个函数 - (void)stop; 如果您在完成扫描仪后运行此功能,您将不会看到问题(第 5 至第 6 次打开页面时它会在 100% CPU 时冻结。)。至少在我的情况下它有效,并希望它也适用于你。
回答by neowhoru
i fixed the issue now with implementing the Diff from the source. If someone of you need it, you can download the compiled zBar SDK with iOS7 Support here.
我现在通过从源头实施 Diff 解决了这个问题。如果您需要它,您可以在此处下载带有 iOS7 支持的编译后的 zBar SDK。
You can just replace the libzbar.a - this should work. But i uploaded the complete SDK as someone may need it too with headers etc.
您可以只替换 libzbar.a - 这应该可以工作。但是我上传了完整的 SDK,因为有人可能也需要它的标题等。
回答by shawn
I was same issue and easily fixed. Do not remember about below code. You must put this code when out of reader view.
我是同样的问题,很容易解决。不记得下面的代码。您必须在阅读器视图之外放置此代码。
[readerview stop];
[读者停止];
cpu over load issue was cause by duplicated camera stream.
cpu 过载问题是由重复的相机流引起的。
回答by Konstantin Heinrich
had same Problems, Scanner seems to be freeze ..
I fixed it like joaquin ...
Make a Property for the reader and when you call it multiple times you can check, if a Object of the reader where initialize ...
Here is what i′m doing:
有同样的问题,扫描仪似乎被冻结了......
我像 joaquin 一样修复了它......
为阅读器创建一个属性,当你多次调用它时你可以检查,如果阅读器的对象初始化......
这是什么我正在做:
- (IBAction)ShowZBarReader
{
// ADD: present a barcode reader that scans from the camera feed
if (!self.reader) {
self.reader = [[ZBarReaderViewController alloc]init];
}
self.reader.readerDelegate = self;
self.reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = self.reader.scanner;
// zus?tliche Configurationen ...
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// stellt Bild zur verfügung
[self presentViewController:self.reader animated:YES completion:nil];
}
Worked perfectly for me ! Hope it helps :)
非常适合我!希望能帮助到你 :)