2014-09-22 78 views
9

我有我的應用程序與ZBar集成。它在iOS 7.1及以下版本中運行良好,但在iOS 8.0設備中,我發現攝像頭視圖首先以黑色顯示。但是,如果我將應用程序發送到後臺狀態,並且我再次將它發送到前臺,打開相機視圖,則它可以工作。有人經歷過這個?ZBar SDK和相機無法在iOS中正常工作8

感謝

+0

我的一位用戶在iphone 6上遇到了同樣的問題。您是否向ZBar開發人員提交了錯誤報告? – nanako 2014-10-03 03:44:26

+0

ZBar使用32位代碼,沒有人將它們移植到64位。這裏是源代碼 - 最後一次提交是2年前 - https://github.com/ZBar/ZBar。它在iOS 6上運行良好。我自己也遇到了這個問題,我正在尋找一個替代SDK--最近的免費第三方SDK是ZXING,但他們也有64位的問題),直到第三方SDK獲得最好的移植選項是嵌入IOS(見下文),它會給你掃描QR碼的能力,並作爲獎勵PDF417和阿茲臺克人代碼 - 但支持一維條碼(UPC,CODE128等)掃描不存在 – Paulo 2015-01-20 01:05:59

+0

我剛試過這個版本的IOS在IOS 8 - 它似乎工作 - https://github.com/TheLevelUp/ZXingObjC – Paulo 2015-01-20 02:08:49

回答

0

如果你只需要QR碼掃描,它更容易與本地的方法來做到這一點:

在你的VC .H補充:

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

而且英寸米

@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 
+0

這並不回答 – JSA986 2014-11-05 14:20:40

+0

問題但你回答這個問題? @ JSA986 – 2014-11-06 12:10:46

+2

因此,與原始問題無關的答案優於無答案?您還沒有回答OP的問題,沒有提及QR掃描儀或請求其他解決方案。問題是關於'Zbar'。我不需要對我的評論發表任何不太正確或不正確的答案 – JSA986 2014-11-06 12:21:13

0

這對我的作品與iOS 8

ZBarReaderViewController *reader = [ZBarReaderViewController new]; 
reader.readerDelegate = self; 
reader.supportedOrientationsMask = ZBarOrientationMaskAll; 
[self presentViewController:reader animated:YES completion:nil]; 
[reader viewWillAppear:NO];`