Zbar SDK and ios7/xcode 5 - App is reaching 100% cpu use and memory more than 100MB

前端 未结 6 957
我寻月下人不归
我寻月下人不归 2020-12-28 09:48

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

相关标签:
6条回答
  • 2020-12-28 09:54

    Solved doing this: in the 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.

    to use it:

    -(void) showqr:(id)sender
    {
        [self presentViewController:readerqr animated:YES completion:nil];
        return;
    }
    

    This way works, no leak, no cpu 100%

    0 讨论(0)
  • 2020-12-28 09:54

    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.

    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.

    http://nerdvision.net/app-development/ios/zbar-sdk

    0 讨论(0)
  • 2020-12-28 09:59

    I solved the problem that Barry Mc G had.

    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.)

    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.

    0 讨论(0)
  • 2020-12-28 10:02

    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.

    0 讨论(0)
  • 2020-12-28 10:12

    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:

    - (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 :)

    0 讨论(0)
  • 2020-12-28 10:15

    After seeing the same issue,

    I moved from

    ZBarReaderViewController

    to

    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.

    But essentially, you need something like this in your 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

    Also, the delegate "method" that gets called, at least in my code, is now (versus the 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.

    0 讨论(0)
提交回复
热议问题