【问题标题】:ZXingObjc Integration IOS ,but didn't work at allZXingObjc 集成 IOS ,但根本不工作
【发布时间】:2015-05-21 06:33:35
【问题描述】:

我已经集成了ZXingObjc 框架,并将ViewController 集成为RootViewControllerViewController.m 中的代码如下:

#import <AudioToolbox/AudioToolbox.h>
#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) ZXCapture *capture;
@property (nonatomic, weak) IBOutlet UIView *scanRectView;
@property (nonatomic, weak) IBOutlet UILabel *decodedLabel;

@end

@implementation ViewController

#pragma mark - View Controller Methods

- (void)dealloc {
    [self.capture.layer removeFromSuperlayer];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.capture = [[ZXCapture alloc] init];
    self.capture.camera = self.capture.back;
    self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;
    self.capture.rotation = 90.0f;

    self.capture.layer.frame = self.view.bounds;
    [self.view.layer addSublayer:self.capture.layer];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.capture.delegate = self;
    self.capture.layer.frame = self.view.bounds;
    self.capture.scanRect = self.scanRectView.frame;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}

#pragma mark - Private Methods

- (NSString *)barcodeFormatToString:(ZXBarcodeFormat)format {
    switch (format) {
        case kBarcodeFormatAztec:
            return @"Aztec";

        case kBarcodeFormatCodabar:
            return @"CODABAR";

        case kBarcodeFormatCode39:
            return @"Code 39";

        case kBarcodeFormatCode93:
            return @"Code 93";

        case kBarcodeFormatCode128:
            return @"Code 128";

        case kBarcodeFormatDataMatrix:
            return @"Data Matrix";

        case kBarcodeFormatEan8:
            return @"EAN-8";

        case kBarcodeFormatEan13:
            return @"EAN-13";

        case kBarcodeFormatITF:
            return @"ITF";

        case kBarcodeFormatPDF417:
            return @"PDF417";

        case kBarcodeFormatQRCode:
            return @"QR Code";

        case kBarcodeFormatRSS14:
            return @"RSS 14";

        case kBarcodeFormatRSSExpanded:
            return @"RSS Expanded";

        case kBarcodeFormatUPCA:
            return @"UPCA";

        case kBarcodeFormatUPCE:
            return @"UPCE";

        case kBarcodeFormatUPCEANExtension:
            return @"UPC/EAN extension";

        default:
            return @"Unknown";
    }
}

#pragma mark - ZXCaptureDelegate Methods


- (void)captureCameraIsReady:(ZXCapture *)capture
{
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);

}

- (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result {

    if (!result) return;
    NSLog(@"%s,%d",__FUNCTION__,__LINE__);
    // We got a result. Display information about the result onscreen.
    NSString *formatString = [self barcodeFormatToString:result.barcodeFormat];
    NSString *display = [NSString stringWithFormat:@"Scanned!\n\nFormat: %@\n\nContents:\n%@", formatString, result.text];
    [self.decodedLabel performSelectorOnMainThread:@selector(setText:) withObject:display waitUntilDone:YES];

    // Vibrate
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

    [self.capture stop];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self.capture start];
    });
}

@end

我发现- (void)captureResult:(ZXCapture *)capture result:(ZXResult *)result这个方法根本不起作用。

接下来,我把同样的代码放到ZXingObjc的例子中,效果很好。 我真的不知道我怎么了。 希望得到您的帮助!

【问题讨论】:

  • 搜索演示和您的项目之间的差异。我刚才试了一下,效果很好
  • 你什么都没说
  • 您找到解决方案了吗?我也有同样的问题

标签: ios zxing qr-code


【解决方案1】:

我遇到了同样的问题。在我的情况下,视图控制器会启动,但永远不会检测到条形码。结果我需要将“-ObjC”添加到“其他链接器标志”。

参考:https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/configuration.html

【讨论】:

    【解决方案2】:

    您的 Viewcontroller.h 文件是否采用了 ZXCapture 协议?像这样的:

        //ViewController.h    
        @interface ViewController: NSObject <ZXCaptureDelegate> //<---- this guy
    
        - (void)yourFunction;
        - (void)anotherFunction;
    
        @end
    

    (我不知道它的真名是什么)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 2014-04-03
      • 2018-05-03
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      相关资源
      最近更新 更多