14

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?

RGRG
  • 166
  • 1
  • 1
  • 6
  • other zbar users also facing same issue. here is link - https://sourceforge.net/p/zbar/discussion/1072195/thread/df4c215a/#b4cc – RGRG Sep 26 '13 at 05:22

6 Answers6

18

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%

Andrew
  • 3,874
  • 5
  • 39
  • 67
  • this works for me. Thanks. ( it means there is leak in the library) – Ram G. Sep 26 '13 at 16:15
  • 1
    You need to show declaration of variables I have no idea what a readerview is. – Alioo Oct 14 '13 at 19:46
  • @joaquin How did your code look before you solved the problem? I've got the same problem but I'm not able to fix it by implementing your code. – nj. Oct 18 '13 at 13:28
  • We start scanning from several different views in our applications and this did not solve it completely. Instead we let the app delegate own the ZBarReaderViewController instance. It doesn't feel like the right way to do it but it worked. – nj. Oct 22 '13 at 12:11
  • This works because `ZBarReaderViewController` gets only instantiated once **if** this owning view controller also only gets instantiated once. Which is a big if, I had to resort to write my own view controller around `ZBarReaderView`, as others have said below. – Pascal Jan 24 '14 at 18:49
7

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.

iPatel
  • 46,010
  • 16
  • 115
  • 137
dlavender
  • 71
  • 2
  • Nothing shows up when I put this in my action but oddly enough my flash turns on? – Alioo Nov 04 '13 at 22:02
  • Good answer! My memory issues were fixed without even having to do anything special to the scanner. I just used the ZBarReaderView and ZBarReaderViewDelegate instead of the ZBarReaderViewController and ZBarReaderDelegate. I start the readerView in viewDidAppear and stop it in viewDidDisapper, which works for my particular application. – Eric Nov 18 '13 at 21:01
4

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.

HMHero
  • 2,333
  • 19
  • 11
3

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

neowhoru
  • 184
  • 5
  • This doesn't work. I have also compiled my own binary using the .diff [here](http://sourceforge.net/p/zbar/patches/36/) which I assume is what you did, but it does not work also – Stephen Groom Oct 21 '13 at 14:40
  • 1
    can you please rebuild the library and add i386 slice. It does not work on simulator – Ram G. Nov 21 '13 at 00:01
0

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.

shawn
  • 1
0

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