Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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?

like image 398
RGRG Avatar asked Sep 26 '13 04:09

RGRG


3 Answers

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%

like image 175
joaquin custodio Avatar answered Nov 09 '22 20:11

joaquin custodio


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.

like image 25
dlavender Avatar answered Nov 09 '22 21:11

dlavender


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.

like image 34
HMHero Avatar answered Nov 09 '22 20:11

HMHero