11

I am developing an app for our local business. I already have the live camera in a UIImageView, now I need to know how to read QR codes from the UIImageView and display the content (0000-KKP0-2013) in a label.

So basically I need a QR code scanner which is reading a QR code and save the content in a String. I already used ZXing ("Zebra Crossing") but it is not compatible with iOS 6 and it won't work. Is there an easy code for getting the QR Code content in a String?

Thank you!

This is the code I am using in my .m file:

#import "ZBarSDK.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize vImagePreview;             

- (void)viewDidUnload
{
    [super viewDidUnload];

    vImagePreview = nil;
}

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


    //----- SHOW LIVE CAMERA PREVIEW -----
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPreset352x288;

    /*CALayer *viewLayer = self.vImagePreview.layer;
    NSLog(@"viewLayer = %@", viewLayer);*/

    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

    captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
    [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

    AVCaptureDevice *device = [self frontCamera];

    NSError *error = nil;
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
    if (!input) {
        // Handle the error appropriately.
        NSLog(@"ERROR: trying to open camera: %@", error);

        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"QReader"
                              message:[NSString stringWithFormat:@"ERROR: Versuch die Kamera zu öffnen ist fehlgeschlagen [%@]",error]
                              delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        alert.tag = 1;

        [alert show];
    }
    [session addInput:input];

    [session startRunning];

    }

- (AVCaptureDevice *)frontCamera {
    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in devices) {
        if ([device position] == AVCaptureDevicePositionFront) {
            return device;
        }
    }
    return nil;
}

Now I need to know how to read the QR code from the vImagePreview with the ZBarSDK. And I cant use a UIPickerView

4

6 に答える 6

9

ZBar を試す: http://zbar.sourceforge.net/iphone/sdkdoc/install.html

iOS 4からiOS 6.1までをサポートするアプリケーションでそれをうまく使用しています

私の場合、ZBarReaderView- を使用して、スキャンしたコードを自動的に検出して返すカメラ プレビューを表示します。

あなたは必要になるでしょう:

#import "ZBarSDK.h"  


ZBarReaderView *readerView;

これを追加 :<ZBarReaderViewDelegate>

その後:

[readerView.scanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ENABLE to:0]; 
readerView.readerDelegate = self;

[readerView start];

- (void)readerView:(ZBarReaderView *)view didReadSymbols: (ZBarSymbolSet *)syms fromImage:(UIImage *)img
{
    for(ZBarSymbol *sym in syms) 
    {  
        NSLog(@"Did read symbols: %@", sym.data);

    }
}

とにかく、次の指示に従ってください。

http://zbar.sourceforge.net/iphone/sdkdoc/tutorial.html

そしてそれを試してみてください - それがあなたのために働くかどうか見てください.

編集

ここで、ここから取ったサンプル プロジェクトをアップロードしました: https://github.com/arciem/ZBarSDK

前面カメラを有効にしました。テスト済み -前面カメラを使用して QR コードを正常に読み取ります。

http://www.speedyshare.com/fkvqt/download/readertest.zip

また

アプリケーションが起動すると - フロントカメラが表示されます - スキャナは 200x200 の大きさで、サブビューとして表示されます。 http://www.speedyshare.com/QZZU5/download/ReaderSample-v3.zip

于 2013-03-10T09:12:35.667 に答える
2

私たちは少し前にこれを調べました。ZBar は良さそうに見えますが、LGPL ライセンスであり、App Store での使用には適していません。結局、私はZXingObjCに行きました。

于 2013-03-10T09:32:50.233 に答える
1

OPは2年前にiOS6をサポートするものを探していましたが、他の人のために、私が行ったこれは組み込みのiOS7機能をラップしています:

https://github.com/mikebuss/MTBBarcodeScanner

于 2015-03-13T14:51:45.397 に答える
0

Appleネイティブに実装された Qr コードで確認してください

于 2015-05-05T04:36:22.140 に答える
0

Swiftでこれを実装しようとしている人。これをチェックしてください: https ://github.com/aeieli/swiftQRCode

いくつかの構文エラーを変更する必要があります。それ以外は iOS 8.1 で完全に動作します

于 2014-11-11T15:54:11.243 に答える