ZBar SDK and camera not working properly in iOS 8
Asked Answered
D

2

9

I have my app integrated with ZBar. It is working perfectly in iOS 7.1 and below, but in iOS 8.0 devices I find that the camera view is firstly shown in black. However, if I send the app to background state and I send it to foreground again, having the camera view open, then it works. Has somebody experienced this?

Thanks

Dehart answered 22/9, 2014 at 7:57 Comment(3)
One of my users is experience the same issue on iphone 6. Have you submitted a bug report to the ZBar developers?Burdine
ZBar is using 32 bit code and no one has ported them to 64 bit yet. Here is the source code - the last commit was 2 years ago - github.com/ZBar/ZBar. It works well on IOS 6. I have this problem myself and I am looking for a replacement SDK - the nearest free 3rd party SDK is ZXING but they have issues with 64 bit as well), Until the 3rd party SDKs get ported the most viable option is the one embedded with IOS (see below) it will give you ability to scan QR Codes and as a bonus PDF417 and Aztec Codes however - support for 1D barcode (UPC, CODE128, etc. ) scanning is not thereNickelodeon
I just tried this version of Zing in IOS 8 - it seems to be working - github.com/TheLevelUp/ZXingObjCNickelodeon
A
0

If you only need QR Code scanning, it's much easier to do this with native means:

In the .h of your VC add:

#import <AVFoundation/AVFoundation.h>
@interface FEQRViewController : UIViewController <AVCaptureMetadataOutputObjectsDelegate>

And in .m

@interface FEQRViewController ()

@property (nonatomic) BOOL isReading;

@property (nonatomic, strong) AVCaptureSession *captureSession;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer;

-(BOOL)startReading;

-(void)stopReading;

@end

@implementation FEQRViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = ....;


    self.isReading = NO;
    self.captureSession = nil;


    // Do any additional setup after loading the view from its nib.
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (!self.isReading) {
        if ([self startReading]) {
            //[self.startButton setTitle:@"Stop" forState:UIControlStateNormal];
            [self.statusLabel setText:@"Scanning for QR Code..." ];
        }
    }
    else{
        [self stopReading];
        [self.startButton setTitle:@"Start!" forState:UIControlStateNormal];
    }

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(BOOL)startReading
{
    NSError *error;
    AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];

    if (!input) {
        NSLog(@"%@", [error localizedDescription]);
        return NO;
    }

    self.captureSession = [[AVCaptureSession alloc] init];
    [self.captureSession addInput:input];

    AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
    [self.captureSession addOutput:captureMetadataOutput];

    dispatch_queue_t dispatchQueue;
    dispatchQueue = dispatch_queue_create("myQueue", NULL);
    [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
    [captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];

    self.videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
    [self.videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.videoPreviewLayer setFrame:self.preview.layer.bounds];
    [self.preview.layer addSublayer:_videoPreviewLayer];

    [_captureSession startRunning];
    return YES;
}

-(void)stopReading
{
    [self.captureSession stopRunning];

    self.captureSession = nil;
    [self.videoPreviewLayer removeFromSuperlayer];

}


-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
    if (metadataObjects != nil && [metadataObjects count] > 0) {

        AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];
        if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {
            [self.statusLabel performSelectorOnMainThread:@selector(setText:) withObject:[metadataObj stringValue] waitUntilDone:NO];
            NSURL *url = [NSURL URLWithString:[metadataObj stringValue]];
            if (url)

                [self performSelectorOnMainThread:@selector(goToURL:) withObject:url waitUntilDone:NO];

            [self performSelectorOnMainThread:@selector(stopReading) withObject:nil waitUntilDone:NO];
            //[self.startButton performSelectorOnMainThread:@selector(setTitle:) withObject:@"Start!" waitUntilDone:NO];
            _isReading = NO;
        }
    }
}

-(void)goToURL:(NSURL *)url
{
   //Handle URL...
}

- (IBAction)startButton:(id)sender {

    if (!self.isReading) {
        if ([self startReading]) {
            [self.startButton setTitle:@"Stop" forState:UIControlStateNormal];
            [self.statusLabel setText:@"Scanning for QR Code..." ];
        }
    }
    else{
        [self stopReading];
        [self.startButton setTitle:@"Start!" forState:UIControlStateNormal];
    }

    _isReading = !_isReading;
}

@end
Amour answered 5/11, 2014 at 13:42 Comment(3)
That doesn't answer the questionPeper
But you answer the question? @PeperAmour
So an answer of no relevance to the original question is preferable to no answer? You have not answered the OP's question, There was no reference to a QR scanner or a request for another solution. The question is about Zbar. I do not need to post an answer for my comments to be any less relevant or correctPeper
E
0

This works for me with iOS 8

ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
[self presentViewController:reader animated:YES completion:nil];
[reader viewWillAppear:NO];`
Exercise answered 24/6, 2015 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.